crash_event_flutter.py 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import time
  2. from collections.abc import Mapping, MutableMapping, Sequence
  3. def get_frames(
  4. sdk_frame_abs_path: str,
  5. system_frame_abs_path: str,
  6. ) -> Sequence[MutableMapping[str, str]]:
  7. frames = [
  8. {
  9. "function": "GestureRecognizer.invokeCallback",
  10. "package": "flutter",
  11. "filename": "recognizer.dart",
  12. "abs_path": "package:flutter/src/gestures/recognizer.dart",
  13. },
  14. {
  15. "function": "_InkResponseState.handleTap",
  16. "package": "flutter",
  17. "filename": "ink_well.dart",
  18. "abs_path": "package:flutter/src/material/ink_well.dart",
  19. },
  20. {
  21. "function": "MainScaffold.build.<fn>",
  22. "package": "sentry_flutter_example",
  23. "filename": "main.dart",
  24. "abs_path": "package:sentry_flutter_example/main.dart",
  25. },
  26. {
  27. "function": "SentryTracer.setTag",
  28. "filename": "sentry_tracer.dart",
  29. "abs_path": sdk_frame_abs_path,
  30. },
  31. {
  32. "function": "List.[]",
  33. "filename": "growable_array.dart",
  34. "abs_path": system_frame_abs_path,
  35. },
  36. ]
  37. return frames
  38. def get_crash_event(
  39. sdk_frame_abs_path="package:sentry/src/sentry_tracer.dart",
  40. system_frame_abs_path="dart:core-patch/growable_array.dart",
  41. **kwargs,
  42. ) -> dict[str, object]:
  43. return get_crash_event_with_frames(
  44. get_frames(sdk_frame_abs_path, system_frame_abs_path),
  45. **kwargs,
  46. )
  47. def get_crash_event_with_frames(frames: Sequence[Mapping[str, str]], **kwargs) -> dict[str, object]:
  48. result = {
  49. "event_id": "0a52a8331d3b45089ebd74f8118d4fa1",
  50. "release": "io.sentry.flutter.sentryFlutterExample@8.2.0+8.2.0",
  51. "platform": "other",
  52. "exception": {
  53. "values": [
  54. {
  55. "type": "RangeError",
  56. "value": "RangeError (index): Invalid value: Not in inclusive range 0..1: 2",
  57. "stacktrace": {"frames": frames},
  58. "mechanism": {"type": "PlatformDispatcher.onError", "handled": True},
  59. }
  60. ]
  61. },
  62. "level": "fatal",
  63. "contexts": {
  64. "device": {
  65. "family": "macOS",
  66. "model": "Mac14,5",
  67. "arch": "arm64",
  68. "simulator": False,
  69. "memory_size": 68719476736,
  70. "free_memory": 839892992,
  71. "usable_memory": 65829797888,
  72. "processor_count": 12,
  73. "type": "device",
  74. },
  75. "os": {
  76. "name": "macOS",
  77. "version": "14.4.1",
  78. "build": "23E224",
  79. "kernel_version": "Darwin Kernel Version 23.4.0: Fri Mar 15 00:12:49 PDT 2024; root:xnu-10063.101.17~1/RELEASE_ARM64_T6020",
  80. "rooted": False,
  81. "theme": "light",
  82. "type": "os",
  83. },
  84. },
  85. "sdk": {"name": "sentry.dart.flutter", "version": "8.2.0"},
  86. "timestamp": time.time(),
  87. "type": "error",
  88. }
  89. result.update(kwargs)
  90. return result