crash_event_dart.py 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import time
  2. from collections.abc import Mapping, MutableMapping, Sequence
  3. def get_frames(
  4. sdk_frame_abs_path: str, system_frame_abs_path: str, sdk_function: str
  5. ) -> Sequence[MutableMapping[str, str]]:
  6. frames = [
  7. {
  8. "function": "GestureRecognizer.invokeCallback",
  9. "package": "flutter",
  10. "filename": "recognizer.dart",
  11. "abs_path": "package:flutter/src/gestures/recognizer.dart",
  12. },
  13. {
  14. "function": "_InkResponseState.handleTap",
  15. "package": "flutter",
  16. "filename": "ink_well.dart",
  17. "abs_path": "package:flutter/src/material/ink_well.dart",
  18. },
  19. {
  20. "function": "MainScaffold.build.<fn>",
  21. "package": "sentry_flutter_example",
  22. "filename": "main.dart",
  23. "abs_path": "package:sentry_flutter_example/main.dart",
  24. },
  25. {
  26. "function": sdk_function,
  27. "filename": "sentry_tracer.dart",
  28. "abs_path": sdk_frame_abs_path,
  29. },
  30. {
  31. "function": "List.[]",
  32. "filename": "growable_array.dart",
  33. "abs_path": system_frame_abs_path,
  34. },
  35. ]
  36. return frames
  37. def get_crash_event(
  38. sdk_frame_abs_path="package:sentry/src/sentry_tracer.dart",
  39. system_frame_abs_path="dart:core-patch/growable_array.dart",
  40. sdk_function="SentryTracer.setTag",
  41. **kwargs,
  42. ) -> dict[str, object]:
  43. return get_crash_event_with_frames(
  44. get_frames(sdk_frame_abs_path, system_frame_abs_path, sdk_function=sdk_function),
  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