crash_event_react_native.py 7.3 KB

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