crash_event_react_native.py 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. import time
  2. from collections.abc import Mapping, MutableMapping, Sequence
  3. def get_frames(filename: str) -> Sequence[MutableMapping[str, str]]:
  4. frames = [
  5. {
  6. "function": "dispatchEvent",
  7. "filename": "/Users/sentry.user/git-repos/sentry-react-native/samples/react-native/node_modules/react-native/Libraries/Renderer/implementations/ReactFabric-dev.js",
  8. "abs_path": "/Users/sentry.user/git-repos/sentry-react-native/samples/react-native/node_modules/react-native/Libraries/Renderer/implementations/ReactFabric-dev.js",
  9. },
  10. {
  11. "function": "Button.props.onPress",
  12. "filename": "/Users/sentry.user/git-repos/sentry-react-native/samples/react-native/src/Screens/HomeScreen.tsx",
  13. "abs_path": "/Users/sentry.user/git-repos/sentry-react-native/samples/react-native/src/Screens/HomeScreen.tsx",
  14. },
  15. {
  16. "function": "community.lib.dosomething",
  17. "filename": "/Users/sentry.user/git-repos/sentry-react-native/samples/react-native/node_modules/react-native-community/Renderer/implementations/ReactFabric-dev.js",
  18. "abs_path": "/Users/sentry.user/git-repos/sentry-react-native/samples/react-native/node_modules/react-native-community/Renderer/implementations/ReactFabric-dev.js",
  19. },
  20. {
  21. "function": "nativeCrash",
  22. "filename": "/Users/sentry.user/git-repos/sentry-react-native/dist/js/sdk.js",
  23. "abs_path": "/Users/sentry.user/git-repos/sentry-react-native/dist/js/sdk.js",
  24. },
  25. {
  26. "function": "ReactNativeClient#nativeCrash",
  27. "module": filename.replace("node_modules/", "").replace(".js", ""),
  28. "filename": filename,
  29. "abs_path": f"app:///{filename}",
  30. },
  31. {
  32. "function": "callFunctionReturnFlushedQueue",
  33. "module": "react-native/Libraries/BatchedBridge/MessageQueue",
  34. "filename": "node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js",
  35. "abs_path": "app:///node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js",
  36. },
  37. {
  38. "function": "processCallbacks",
  39. "module": "react-native-community/BatchedBridge/MessageQueue",
  40. "filename": "node_modules/react-native-community/BatchedBridge/MessageQueue.js",
  41. "abs_path": "app:///node_modules/react-native-community/BatchedBridge/MessageQueue.js",
  42. },
  43. ]
  44. return frames
  45. def get_exception(
  46. frames: Sequence[Mapping[str, str]],
  47. mechanism_type: str = "onerror",
  48. ) -> dict[str, object]:
  49. return {
  50. "type": "Error",
  51. "value": "Uncaught Thrown Error",
  52. "stacktrace": {"frames": frames},
  53. "mechanism": {"type": mechanism_type, "handled": False},
  54. }
  55. def get_crash_event(
  56. filename="/Users/sentry.user/git-repos/sentry-react-native/dist/js/client.js", **kwargs
  57. ) -> dict[str, object]:
  58. return get_crash_event_with_frames(get_frames(filename=filename), **kwargs)
  59. def get_crash_event_with_frames(frames: Sequence[Mapping[str, str]], **kwargs) -> dict[str, object]:
  60. result = {
  61. "event_id": "150d5b0b4f3a4797a3cd1345374ac484",
  62. "release": "com.samplenewarchitecture@1.0+1",
  63. "dist": "1",
  64. "platform": "javascript",
  65. "message": "",
  66. "environment": "dev",
  67. "exception": {"values": [get_exception(frames)]},
  68. "key_id": "3554525",
  69. "level": "fatal",
  70. "contexts": {
  71. "app": {
  72. "app_start_time": "2024-01-11T10:30:29.281Z",
  73. "app_identifier": "com.samplenewarchitecture",
  74. "app_name": "sampleNewArchitecture",
  75. "app_version": "1.0",
  76. "app_build": "1",
  77. "in_foreground": True,
  78. "view_names": ["Home"],
  79. "permissions": {
  80. "ACCESS_NETWORK_STATE": "granted",
  81. "ACCESS_WIFI_STATE": "granted",
  82. "DYNAMIC_RECEIVER_NOT_EXPORTED_PERMISSION": "granted",
  83. "INTERNET": "granted",
  84. "SYSTEM_ALERT_WINDOW": "not_granted",
  85. },
  86. "type": "app",
  87. },
  88. "device": {
  89. "family": "sdk_gphone64_arm64",
  90. "model": "sdk_gphone64_arm64",
  91. "model_id": "UPB2.230407.019",
  92. "battery_level": 100.0,
  93. "orientation": "portrait",
  94. "manufacturer": "Google",
  95. "brand": "google",
  96. "screen_width_pixels": 1080,
  97. "screen_height_pixels": 2209,
  98. "screen_density": 2.625,
  99. "screen_dpi": 420,
  100. "online": True,
  101. "charging": False,
  102. "low_memory": False,
  103. "simulator": True,
  104. "memory_size": 2074669056,
  105. "free_memory": 607039488,
  106. "storage_size": 6228115456,
  107. "free_storage": 4940427264,
  108. "boot_time": "2024-01-11T09:56:37.070Z",
  109. "timezone": "Europe/Vienna",
  110. "locale": "en_US",
  111. "processor_count": 4,
  112. "processor_frequency": 0,
  113. "archs": ["arm64-v8a"],
  114. "battery_temperature": 25,
  115. "connection_type": "wifi",
  116. "id": "64b13018-2922-4938-92b1-3135861a69c8",
  117. "language": "en",
  118. "type": "device",
  119. },
  120. "os": {
  121. "name": "Android",
  122. "version": "13",
  123. "build": "sdk_gphone64_arm64-userdebug UpsideDownCake UPB2.230407.019 10170211 dev-keys",
  124. "kernel_version": "6.1.21-android14-3-01811-g9e35a21ec03f-ab9850788",
  125. "rooted": False,
  126. "type": "os",
  127. },
  128. },
  129. "logger": "",
  130. "sdk": {
  131. "name": "sentry.javascript.react-native",
  132. "version": "5.15.2",
  133. "integrations": [
  134. "ModulesLoader",
  135. "ReactNativeErrorHandlers",
  136. "Release",
  137. "InboundFilters",
  138. "FunctionToString",
  139. "Breadcrumbs",
  140. "HttpContext",
  141. "NativeLinkedErrors",
  142. "EventOrigin",
  143. "SdkInfo",
  144. "ReactNativeInfo",
  145. "DebugSymbolicator",
  146. "RewriteFrames",
  147. "DeviceContext",
  148. "HermesProfiling",
  149. "ReactNativeTracing",
  150. "Screenshot",
  151. "ViewHierarchy",
  152. "HttpClient",
  153. "react-navigation-v5",
  154. "ReactNativeUserInteractionTracing",
  155. "ReactNativeProfiler",
  156. "TouchEventBoundary",
  157. ],
  158. "packages": [
  159. {"name": "sentry.java.android.react-native", "version": "6.34.0"},
  160. {"name": "npm:@sentry/react-native", "version": "5.15.2"},
  161. ],
  162. },
  163. "timestamp": time.time(),
  164. "type": "error",
  165. "user": {
  166. "email": "philipp@example.com",
  167. "ip_address": "85.193.160.231",
  168. "geo": {
  169. "country_code": "AT",
  170. "city": "Diersbach",
  171. "subdivision": "Upper Austria",
  172. "region": "Austria",
  173. },
  174. },
  175. "version": "7",
  176. }
  177. result.update(kwargs)
  178. return result