crash_event_android.py 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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",
  44. system_frame_module="java.lang.reflect.Method",
  45. **kwargs,
  46. ) -> dict[str, object]:
  47. return get_crash_event_with_frames(
  48. get_frames(sdk_frame_module, system_frame_module),
  49. **kwargs,
  50. )
  51. def get_apex_frames(
  52. apex_frame_function: str,
  53. apex_frame_package: str,
  54. system_frame_package: str,
  55. ) -> Sequence[MutableMapping[str, str]]:
  56. frames = [
  57. {
  58. "function": "__pthread_start",
  59. "raw_function": "__pthread_start(void*)",
  60. "symbol": "_ZL15__pthread_startPv",
  61. "package": "/apex/com.android.runtime/lib/bionic/libc.so",
  62. },
  63. {
  64. "function": "__start_thread",
  65. "symbol": "__start_thread",
  66. "package": "/apex/com.android.art/lib64/bionic/libc.so",
  67. },
  68. {
  69. "function": apex_frame_function,
  70. "symbol": apex_frame_function,
  71. "package": apex_frame_package,
  72. },
  73. {
  74. "function": "invoke",
  75. "package": system_frame_package,
  76. },
  77. ]
  78. return frames
  79. def get_apex_crash_event(
  80. apex_frame_function="__start_thread",
  81. apex_frame_package="/apex/com.android.art/lib64/bionic/libc.so",
  82. system_frame_package="/apex/com.android.art/lib64/libart.so",
  83. **kwargs,
  84. ) -> dict[str, object]:
  85. return get_crash_event_with_frames(
  86. get_apex_frames(apex_frame_function, apex_frame_package, system_frame_package),
  87. **kwargs,
  88. )
  89. def get_crash_event_with_frames(frames: Sequence[Mapping[str, str]], **kwargs) -> dict[str, object]:
  90. result = {
  91. "event_id": "0a52a8331d3b45089ebd74f8118d4fa1",
  92. "release": "io.sentry.samples.android@7.4.0+2",
  93. "dist": "2",
  94. "platform": "java",
  95. "environment": "debug",
  96. "exception": {
  97. "values": [
  98. {
  99. "type": "IllegalArgumentException",
  100. "value": "SDK Crash",
  101. "module": "java.lang",
  102. "stacktrace": {"frames": frames},
  103. "mechanism": {"type": "onerror", "handled": False},
  104. }
  105. ]
  106. },
  107. "key_id": "1336851",
  108. "level": "fatal",
  109. "contexts": {
  110. "device": {
  111. "name": "sdk_gphone64_arm64",
  112. "family": "sdk_gphone64_arm64",
  113. "model": "sdk_gphone64_arm64",
  114. "simulator": True,
  115. },
  116. "os": {
  117. "name": "Android",
  118. "version": "13",
  119. "build": "sdk_gphone64_arm64-userdebug UpsideDownCake UPB2.230407.019 10170211 dev-keys",
  120. "kernel_version": "6.1.21-android14-3-01811-g9e35a21ec03f-ab9850788",
  121. "rooted": False,
  122. "type": "os",
  123. },
  124. },
  125. "sdk": {"name": "sentry.java.android", "version": "7.4.0"},
  126. "timestamp": time.time(),
  127. "type": "error",
  128. }
  129. result.update(kwargs)
  130. return result