crash_event_react_native.py 7.3 KB

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