crash_event.py 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. from typing import Any, Collection, Dict, Mapping, Sequence
  2. IN_APP_FRAME = {
  3. "function": "LoginViewController.viewDidAppear",
  4. "raw_function": "LoginViewController.viewDidAppear(Bool)",
  5. "symbol": "$s8Sentry9LoginViewControllerC13viewDidAppearyySbF",
  6. "package": "SentryApp",
  7. "filename": "LoginViewController.swift",
  8. "abs_path": "/Users/sentry/git/iOS/Sentry/LoggedOut/LoginViewController.swift",
  9. "lineno": 196,
  10. "in_app": True,
  11. "image_addr": "0x100260000",
  12. "instruction_addr": "0x102b16630",
  13. "symbol_addr": "0x100260000",
  14. }
  15. def get_sentry_frame(function: str, in_app: bool = False) -> Mapping[str, Any]:
  16. return {
  17. "function": function,
  18. "package": "Sentry",
  19. "in_app": in_app,
  20. "image_addr": "0x100304000",
  21. }
  22. def get_frames(function: str, sentry_frame_in_app: bool = False) -> Sequence[Mapping[str, Any]]:
  23. frames = [
  24. get_sentry_frame(function, sentry_frame_in_app),
  25. {
  26. "function": "LoginViewController.viewDidAppear",
  27. "symbol": "$s8Sentry9LoginViewControllerC13viewDidAppearyySbF",
  28. "package": "SentryApp",
  29. "in_app": True,
  30. "filename": "LoginViewController.swift",
  31. "image_addr": "0x100260000",
  32. },
  33. IN_APP_FRAME,
  34. {
  35. "function": "-[UIViewController _setViewAppearState:isAnimating:]",
  36. "symbol": "-[UIViewController _setViewAppearState:isAnimating:]",
  37. "package": "UIKitCore",
  38. "in_app": False,
  39. "image_addr": "0x1a4e8f000",
  40. },
  41. {
  42. "function": "-[UIViewController __viewDidAppear:]",
  43. "symbol": "-[UIViewController __viewDidAppear:]",
  44. "package": "UIKitCore",
  45. "in_app": False,
  46. "image_addr": "0x1a4e8f000",
  47. },
  48. {
  49. "function": "-[UIViewController _endAppearanceTransition:]",
  50. "symbol": "-[UIViewController _endAppearanceTransition:]",
  51. "package": "UIKitCore",
  52. "in_app": False,
  53. "image_addr": "0x1a4e8f000",
  54. },
  55. {
  56. "function": "-[UINavigationController navigationTransitionView:didEndTransition:fromView:toView:]",
  57. "symbol": "-[UINavigationController navigationTransitionView:didEndTransition:fromView:toView:]",
  58. "package": "UIKitCore",
  59. "in_app": False,
  60. "image_addr": "0x1a4e8f000",
  61. },
  62. {
  63. "function": "__49-[UINavigationController _startCustomTransition:]_block_invoke",
  64. "symbol": "__49-[UINavigationController _startCustomTransition:]_block_invoke",
  65. "package": "UIKitCore",
  66. "in_app": False,
  67. "image_addr": "0x1a4e8f000",
  68. },
  69. ]
  70. # The frames have to be ordered from caller to callee, or oldest to youngest.
  71. # The last frame is the one creating the exception.
  72. # As we usually look at stacktraces from youngest to oldest, we reverse the order.
  73. return frames[::-1]
  74. def get_crash_event(handled=False, function="-[Sentry]", **kwargs) -> Dict[str, Collection[str]]:
  75. return get_crash_event_with_frames(get_frames(function), handled=handled, **kwargs)
  76. def get_crash_event_with_frames(
  77. frames: Sequence[Mapping[str, Any]], handled=False, **kwargs
  78. ) -> Dict[str, Collection[str]]:
  79. result = {
  80. "event_id": "80e3496eff734ab0ac993167aaa0d1cd",
  81. "release": "5.222.5",
  82. "type": "error",
  83. "level": "fatal",
  84. "platform": "cocoa",
  85. "tags": {"level": "fatal"},
  86. "exception": {
  87. "values": [
  88. {
  89. "stacktrace": {
  90. "frames": frames,
  91. },
  92. "type": "SIGABRT",
  93. "mechanism": {"handled": handled},
  94. }
  95. ]
  96. },
  97. "breadcrumbs": {
  98. "values": [
  99. {
  100. "timestamp": 1675900265.0,
  101. "type": "debug",
  102. "category": "started",
  103. "level": "info",
  104. "message": "Breadcrumb Tracking",
  105. },
  106. ]
  107. },
  108. "contexts": {
  109. "app": {
  110. "app_start_time": "2023-02-08T23:51:05Z",
  111. "device_app_hash": "8854fe9e3d4e4a66493baee798bfae0228efabf1",
  112. "build_type": "app store",
  113. "app_identifier": "com.some.company.io",
  114. "app_name": "SomeCompany",
  115. "app_version": "5.222.5",
  116. "app_build": "21036",
  117. "app_id": "397D4F75-6C01-32D1-BF46-62098979E470",
  118. "type": "app",
  119. },
  120. "device": {
  121. "family": "iOS",
  122. "model": "iPhone14,8",
  123. "model_id": "D28AP",
  124. "arch": "arm64e",
  125. "memory_size": 5944508416,
  126. "free_memory": 102154240,
  127. "usable_memory": 4125687808,
  128. "storage_size": 127854202880,
  129. "boot_time": "2023-02-01T05:21:23Z",
  130. "timezone": "PST",
  131. "type": "device",
  132. },
  133. "os": {
  134. "name": "iOS",
  135. "version": "16.3",
  136. "build": "20D47",
  137. "kernel_version": "Darwin Kernel Version 22.3.0: Wed Jan 4 21:25:19 PST 2023; root:xnu-8792.82.2~1/RELEASE_ARM64_T8110",
  138. "rooted": False,
  139. "type": "os",
  140. },
  141. },
  142. "debug_meta": {
  143. "images": [
  144. {
  145. "code_file": "/private/var/containers/Bundle/Application/895DA2DE-5FE3-44A0-8C0F-900519EA5516/iOS-Swift.app/iOS-Swift",
  146. "debug_id": "aa8a3697-c88a-36f9-a687-3d3596568c8d",
  147. "arch": "arm64",
  148. "image_addr": "0x100260000",
  149. "image_size": 180224,
  150. "image_vmaddr": "0x100000000",
  151. "type": "macho",
  152. },
  153. {
  154. "code_file": "/private/var/containers/Bundle/Application/9EB557CD-D653-4F51-BFCE-AECE691D4347/iOS-Swift.app/Frameworks/Sentry.framework/Sentry",
  155. "debug_id": "e2623c4d-79c5-3cdf-90ab-2cf44e026bdd",
  156. "arch": "arm64",
  157. "image_addr": "0x100304000",
  158. "image_size": 802816,
  159. "type": "macho",
  160. },
  161. {
  162. "code_file": "/System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore",
  163. "debug_id": "b0858d8e-7220-37bf-873f-ecc2b0a358c3",
  164. "arch": "arm64e",
  165. "image_addr": "0x1a4e8f000",
  166. "image_size": 25309184,
  167. "image_vmaddr": "0x188ff7000",
  168. "type": "macho",
  169. },
  170. {
  171. "code_file": "/System/Library/Frameworks/CFNetwork.framework/CFNetwork",
  172. "debug_id": "b2273be9-538a-3f56-b9c7-801f39550f58",
  173. "arch": "arm64e",
  174. "image_addr": "0x1a3e32000",
  175. "image_size": 3977216,
  176. "image_vmaddr": "0x187f9a000",
  177. "in_app": False,
  178. "type": "macho",
  179. },
  180. ]
  181. },
  182. "environment": "test-app",
  183. "sdk": {
  184. "name": "sentry.cocoa",
  185. "version": "8.1.0",
  186. "integrations": [
  187. "Crash",
  188. "PerformanceTracking",
  189. "MetricKit",
  190. "WatchdogTerminationTracking",
  191. "ViewHierarchy",
  192. "NetworkTracking",
  193. "ANRTracking",
  194. "AutoBreadcrumbTracking",
  195. "FramesTracking",
  196. "AppStartTracking",
  197. "Screenshot",
  198. "FileIOTracking",
  199. "UIEventTracking",
  200. "AutoSessionTracking",
  201. "CoreDataTracking",
  202. "PreWarmedAppStartTracing",
  203. ],
  204. },
  205. "threads": {
  206. "values": [
  207. {
  208. "id": 0,
  209. "stacktrace": {
  210. "frames": [
  211. {
  212. "function": "<redacted>",
  213. "in_app": False,
  214. "data": {"symbolicator_status": "unknown_image"},
  215. "image_addr": "0x0",
  216. "instruction_addr": "0x1129be52e",
  217. "symbol_addr": "0x0",
  218. },
  219. {
  220. "function": "<redacted>",
  221. "in_app": False,
  222. "data": {"symbolicator_status": "unknown_image"},
  223. "image_addr": "0x0",
  224. "instruction_addr": "0x104405f21",
  225. "symbol_addr": "0x0",
  226. },
  227. ],
  228. },
  229. "raw_stacktrace": {
  230. "frames": [
  231. {
  232. "function": "<redacted>",
  233. "in_app": False,
  234. "image_addr": "0x0",
  235. "instruction_addr": "0x1129be52e",
  236. "symbol_addr": "0x0",
  237. },
  238. {
  239. "function": "<redacted>",
  240. "in_app": False,
  241. "image_addr": "0x0",
  242. "instruction_addr": "0x104405f21",
  243. "symbol_addr": "0x0",
  244. },
  245. ],
  246. },
  247. "crashed": True,
  248. }
  249. ]
  250. },
  251. "user": {
  252. "id": "803F5C87-0F8B-41C7-8499-27BD71A92738",
  253. "ip_address": "192.168.0.1",
  254. "geo": {"country_code": "US", "region": "United States"},
  255. },
  256. "logger": "my.logger.name",
  257. }
  258. result.update(kwargs)
  259. return result