crash_event_android.py 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import time
  2. from collections.abc import Mapping, MutableMapping, Sequence
  3. def get_frames(
  4. sdk_frame_module: str, system_frame_module: str
  5. ) -> Sequence[MutableMapping[str, str]]:
  6. frames = [
  7. {
  8. "function": "main",
  9. "module": "android.app.ActivityThread",
  10. "filename": "ActivityThread.java",
  11. "abs_path": "ActivityThread.java",
  12. },
  13. {
  14. "function": "handleCallback",
  15. "module": "android.os.Handler",
  16. "filename": "Handler.java",
  17. "abs_path": "Handler.java",
  18. },
  19. {
  20. "function": "performClickInternal",
  21. "module": "android.view.View",
  22. "filename": "View.java",
  23. "abs_path": "View.java",
  24. },
  25. {
  26. "function": "onClick",
  27. "module": "com.some.samples.android.MainActivity$$ExternalSyntheticLambda8",
  28. },
  29. {
  30. "function": "captureMessage",
  31. "module": sdk_frame_module,
  32. "filename": "Hub.java",
  33. "abs_path": "Hub.java",
  34. },
  35. {
  36. "function": "invoke",
  37. "module": system_frame_module,
  38. "filename": "Method.java",
  39. },
  40. ]
  41. return frames
  42. def get_crash_event(
  43. sdk_frame_module="io.sentry.Hub", system_frame_module="java.lang.reflect.Method", **kwargs
  44. ) -> dict[str, object]:
  45. return get_crash_event_with_frames(
  46. get_frames(sdk_frame_module, system_frame_module),
  47. **kwargs,
  48. )
  49. def get_crash_event_with_frames(frames: Sequence[Mapping[str, str]], **kwargs) -> dict[str, object]:
  50. result = {
  51. "event_id": "0a52a8331d3b45089ebd74f8118d4fa1",
  52. "release": "io.sentry.samples.android@7.4.0+2",
  53. "dist": "2",
  54. "platform": "java",
  55. "environment": "debug",
  56. "exception": {
  57. "values": [
  58. {
  59. "type": "IllegalArgumentException",
  60. "value": "SDK Crash",
  61. "module": "java.lang",
  62. "stacktrace": {"frames": frames},
  63. "mechanism": {"type": "onerror", "handled": False},
  64. }
  65. ]
  66. },
  67. "key_id": "1336851",
  68. "level": "fatal",
  69. "contexts": {
  70. "device": {
  71. "name": "sdk_gphone64_arm64",
  72. "family": "sdk_gphone64_arm64",
  73. "model": "sdk_gphone64_arm64",
  74. "simulator": True,
  75. },
  76. "os": {
  77. "name": "Android",
  78. "version": "13",
  79. "build": "sdk_gphone64_arm64-userdebug UpsideDownCake UPB2.230407.019 10170211 dev-keys",
  80. "kernel_version": "6.1.21-android14-3-01811-g9e35a21ec03f-ab9850788",
  81. "rooted": False,
  82. "type": "os",
  83. },
  84. },
  85. "sdk": {"name": "sentry.java.android", "version": "7.4.0"},
  86. "timestamp": time.time(),
  87. "type": "error",
  88. }
  89. result.update(kwargs)
  90. return result