apple-ios.tsx 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  1. import ExternalLink from 'sentry/components/links/externalLink';
  2. import Link from 'sentry/components/links/link';
  3. import List from 'sentry/components/list/';
  4. import ListItem from 'sentry/components/list/listItem';
  5. import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  6. import type {
  7. Docs,
  8. DocsParams,
  9. OnboardingConfig,
  10. } from 'sentry/components/onboarding/gettingStartedDoc/types';
  11. import {appleFeedbackOnboarding} from 'sentry/gettingStartedDocs/apple/apple-macos';
  12. import {t, tct} from 'sentry/locale';
  13. type Params = DocsParams;
  14. const getInstallSnippet = () =>
  15. `brew install getsentry/tools/sentry-wizard && sentry-wizard -i ios`;
  16. const getExperimentalFeaturesSnippetSwift = () => `
  17. import Sentry
  18. SentrySDK.start { options in
  19. // ...
  20. // Enable all experimental features
  21. options.attachViewHierarchy = true
  22. options.enableMetricKit = true
  23. options.enableTimeToFullDisplayTracing = true
  24. options.swiftAsyncStacktraces = true
  25. options.enableAppLaunchProfiling = true
  26. }`;
  27. const getExperimentalFeaturesSnippetObjC = () => `
  28. @import Sentry;
  29. [SentrySDK startWithConfigureOptions:^(SentryOptions *options) {
  30. // ...
  31. // Enable all experimental features
  32. options.attachViewHierarchy = YES;
  33. options.enableMetricKit = YES;
  34. options.enableTimeToFullDisplayTracing = YES;
  35. options.swiftAsyncStacktraces = YES;
  36. options.enableAppLaunchProfiling = YES;
  37. }];`;
  38. const getConfigureMetricsSnippetSwift = (params: Params) => `
  39. import Sentry
  40. SentrySDK.start { options in
  41. options.dsn = "${params.dsn}"
  42. options.enableMetrics = true
  43. }`;
  44. const getConfigureMetricsSnippetObjC = (params: Params) => `
  45. @import Sentry;
  46. [SentrySDK startWithConfigureOptions:^(SentryOptions * options) {
  47. options.Dsn = @"${params.dsn}";
  48. options.enableMetrics = YES;
  49. }];`;
  50. const getVerifyMetricsSnippetSwift = () => `
  51. import Sentry
  52. // Incrementing a counter by one for each button click.
  53. SentrySDK.metrics
  54. .increment(key: "button_login_click",
  55. value: 1.0,
  56. tags: ["screen": "login"]
  57. )
  58. // Add '150' to a distribution used to track the loading time.
  59. SentrySDK.metrics
  60. .distribution(key: "image_download_duration",
  61. value: 150.0,
  62. unit: MeasurementUnitDuration.millisecond,
  63. tags: ["screen": "login"]
  64. )
  65. // Adding '1' to a gauge used to track the loading time.
  66. SentrySDK.metrics
  67. .gauge(key: "page_load",
  68. value: 1.0,
  69. unit: MeasurementUnitDuration.millisecond,
  70. tags: ["screen": "login"]
  71. )
  72. // Add 'jane' to a set
  73. // used for tracking the number of users that viewed a page.
  74. SentrySDK.metrics
  75. .set(key: "user_view",
  76. value: "jane",
  77. unit: MeasurementUnit(unit: "username"),
  78. tags: ["screen": "login"]
  79. )`;
  80. const getVerifyMetricsSnippetObjC = () => `
  81. @import Sentry;
  82. // Incrementing a counter by one for each button click.
  83. [SentrySDK.metrics
  84. incrementWithKey :@"button_login_click"
  85. value: 1.0
  86. unit: SentryMeasurementUnit.none
  87. tags: @{ @"screen" : @"login" }
  88. ];
  89. // Add '150' to a distribution used to track the loading time.
  90. [SentrySDK.metrics
  91. distributionWithKey: @"image_download_duration"
  92. value: 150.0
  93. unit: SentryMeasurementUnitDuration.millisecond
  94. tags: @{ @"screen" : @"login" }
  95. ];
  96. // Adding '1' to a gauge used to track the loading time.
  97. [SentrySDK.metrics
  98. gaugeWithKey: @"page_load"
  99. value: 1.0
  100. unit: SentryMeasurementUnitDuration.millisecond
  101. tags: @{ @"screen" : @"login" }
  102. ];
  103. // Add 'jane' to a set
  104. // used for tracking the number of users that viewed a page.
  105. [SentrySDK.metrics
  106. setWithKey :@"user_view"
  107. value: @"jane"
  108. unit: [[SentryMeasurementUnit alloc] initWithUnit:@"username"]
  109. tags: @{ @"screen" : @"login" }
  110. ];`;
  111. const onboarding: OnboardingConfig = {
  112. install: () => [
  113. {
  114. type: StepType.INSTALL,
  115. description: (
  116. <p>
  117. {tct(
  118. 'Add Sentry automatically to your app with the [wizardLink:Sentry wizard] (call this inside your project directory).',
  119. {
  120. wizardLink: (
  121. <ExternalLink href="https://docs.sentry.io/platforms/apple/guides/ios/#install" />
  122. ),
  123. }
  124. )}
  125. </p>
  126. ),
  127. configurations: [
  128. {
  129. language: 'bash',
  130. code: getInstallSnippet(),
  131. },
  132. ],
  133. },
  134. ],
  135. configure: () => [
  136. {
  137. type: StepType.CONFIGURE,
  138. description: t('The Sentry wizard will automatically patch your application:'),
  139. configurations: [
  140. {
  141. description: (
  142. <List symbol="bullet">
  143. <ListItem>
  144. {t('Install the Sentry SDK via Swift Package Manager or Cocoapods')}
  145. </ListItem>
  146. <ListItem>
  147. {tct(
  148. 'Update your [appDelegate: AppDelegate] or SwiftUI App Initializer with the default Sentry configuration and an example error',
  149. {
  150. appDelegate: <code />,
  151. }
  152. )}
  153. </ListItem>
  154. <ListItem>
  155. {tct(
  156. 'Add a new [phase: Upload Debug Symbols] phase to your [xcodebuild: xcodebuild] build script',
  157. {
  158. phase: <code />,
  159. xcodebuild: <code />,
  160. }
  161. )}
  162. </ListItem>
  163. <ListItem>
  164. {tct(
  165. 'Create [sentryclirc: .sentryclirc] with an auth token to upload debug symbols (this file is automatically added to [gitignore: .gitignore])',
  166. {
  167. sentryclirc: <code />,
  168. gitignore: <code />,
  169. }
  170. )}
  171. </ListItem>
  172. <ListItem>
  173. {t(
  174. "When you're using Fastlane, it will add a Sentry lane for uploading debug symbols"
  175. )}
  176. </ListItem>
  177. </List>
  178. ),
  179. additionalInfo: tct(
  180. 'Alternatively, you can also [manualSetupLink:set up the SDK manually].',
  181. {
  182. manualSetupLink: (
  183. <ExternalLink href="https://docs.sentry.io/platforms/apple/guides/ios/manual-setup/" />
  184. ),
  185. stepsBelow: <strong />,
  186. }
  187. ),
  188. },
  189. ],
  190. },
  191. ],
  192. verify: () => [
  193. {
  194. type: StepType.VERIFY,
  195. description: t(
  196. 'The Sentry wizard automatically adds a code snippet that captures a message to your project. Simply run your app and you should see this message in your Sentry project.'
  197. ),
  198. },
  199. {
  200. title: t('Experimental Features'),
  201. description: tct(
  202. 'Want to play with some new features? Try out our experimental features for [vh: View Hierarchy], [ttfd: Time to Full Display (TTFD)], [metricKit: MetricKit], [prewarmedAppStart: Prewarmed App Start Tracing], and [asyncStacktraces: Swift Async Stacktraces]. Experimental features are still a work-in-progress and may have bugs. We recognize the irony. [break] Let us know if you have feedback through [gh: GitHub issues].',
  203. {
  204. vh: (
  205. <ExternalLink href="https://docs.sentry.io/platforms/apple/guides/ios/enriching-events/viewhierarchy/" />
  206. ),
  207. ttfd: (
  208. <ExternalLink href="https://docs.sentry.io/platforms/apple/guides/ios/performance/instrumentation/automatic-instrumentation/#time-to-full-display" />
  209. ),
  210. metricKit: (
  211. <ExternalLink href="https://docs.sentry.io/platforms/apple/guides/watchos/configuration/metric-kit/" />
  212. ),
  213. prewarmedAppStart: (
  214. <ExternalLink href="https://docs.sentry.io/platforms/apple/performance/instrumentation/automatic-instrumentation/#prewarmed-app-start-tracing" />
  215. ),
  216. asyncStacktraces: (
  217. <ExternalLink href="https://docs.sentry.io/platforms/apple/guides/ios/#stitch-together-swift-concurrency-stack-traces" />
  218. ),
  219. gh: <ExternalLink href="https://github.com/getsentry/sentry-cocoa/issues" />,
  220. break: <br />,
  221. }
  222. ),
  223. configurations: [
  224. {
  225. code: [
  226. {
  227. label: 'Swift',
  228. value: 'swift',
  229. language: 'swift',
  230. code: getExperimentalFeaturesSnippetSwift(),
  231. },
  232. {
  233. label: 'Objective-C',
  234. value: 'c',
  235. language: 'c',
  236. code: getExperimentalFeaturesSnippetObjC(),
  237. },
  238. ],
  239. },
  240. ],
  241. },
  242. ],
  243. nextSteps: () => [
  244. {
  245. id: 'cocoapods-carthage',
  246. name: t('CocoaPods/Carthage'),
  247. description: t(
  248. 'Learn about integrating Sentry into your project using CocoaPods or Carthage.'
  249. ),
  250. link: 'https://docs.sentry.io/platforms/apple/install/',
  251. },
  252. {
  253. id: 'debug-symbols',
  254. name: t('Debug Symbols'),
  255. description: t('Symbolicate and get readable stacktraces in your Sentry errors.'),
  256. link: 'https://docs.sentry.io/platforms/apple/dsym/',
  257. },
  258. {
  259. id: 'swiftui',
  260. name: t('SwiftUI'),
  261. description: t('Learn about our first class integration with SwiftUI.'),
  262. link: 'https://docs.sentry.io/platforms/apple/performance/instrumentation/swiftui-instrumentation/',
  263. },
  264. {
  265. id: 'profiling',
  266. name: t('Profiling'),
  267. description: t(
  268. 'Collect and analyze performance profiles from real user devices in production.'
  269. ),
  270. link: 'https://docs.sentry.io/platforms/apple/profiling/',
  271. },
  272. ],
  273. };
  274. const metricsOnboarding: OnboardingConfig = {
  275. install: (params: DocsParams) => [
  276. {
  277. type: StepType.INSTALL,
  278. description: tct(
  279. 'You need Sentry Cocoa SDK version [codeVersion:8.23.0] or higher. Learn more about installation methods in our [docsLink:full documentation].',
  280. {
  281. codeVersion: <code />,
  282. docsLink: <Link to={`/projects/${params.projectSlug}/getting-started/`} />,
  283. }
  284. ),
  285. configurations: [
  286. {
  287. language: 'yml',
  288. partialLoading: params.sourcePackageRegistries?.isLoading,
  289. code: getInstallSnippet(),
  290. },
  291. ],
  292. },
  293. ],
  294. configure: (params: DocsParams) => [
  295. {
  296. type: StepType.CONFIGURE,
  297. description: t(
  298. 'To enable capturing metrics, you need to enable the metrics feature.'
  299. ),
  300. configurations: [
  301. {
  302. code: [
  303. {
  304. label: 'Swift',
  305. value: 'swift',
  306. language: 'swift',
  307. code: getConfigureMetricsSnippetSwift(params),
  308. },
  309. {
  310. label: 'Objective-C',
  311. value: 'c',
  312. language: 'c',
  313. code: getConfigureMetricsSnippetObjC(params),
  314. },
  315. ],
  316. },
  317. ],
  318. },
  319. ],
  320. verify: () => [
  321. {
  322. type: StepType.VERIFY,
  323. description: tct(
  324. "Then you'll be able to add metrics as [codeCounters:counters], [codeSets:sets], [codeDistribution:distributions], and [codeGauge:gauges]. These are available under the [codeNamespace:SentrySDK.metrics()] namespace. Try out this example:",
  325. {
  326. codeCounters: <code />,
  327. codeSets: <code />,
  328. codeDistribution: <code />,
  329. codeGauge: <code />,
  330. codeNamespace: <code />,
  331. }
  332. ),
  333. configurations: [
  334. {
  335. configurations: [
  336. {
  337. code: [
  338. {
  339. label: 'Swift',
  340. value: 'swift',
  341. language: 'swift',
  342. code: getVerifyMetricsSnippetSwift(),
  343. },
  344. {
  345. label: 'Objective-C',
  346. value: 'c',
  347. language: 'c',
  348. code: getVerifyMetricsSnippetObjC(),
  349. },
  350. ],
  351. },
  352. ],
  353. },
  354. {
  355. description: t(
  356. 'With a bit of delay you can see the data appear in the Sentry UI.'
  357. ),
  358. },
  359. {
  360. description: tct(
  361. 'Learn more about metrics and how to configure them, by reading the [docsLink:docs].',
  362. {
  363. docsLink: (
  364. <ExternalLink href="https://docs.sentry.io/platforms/apple/metrics/" />
  365. ),
  366. }
  367. ),
  368. },
  369. ],
  370. },
  371. ],
  372. };
  373. const docs: Docs = {
  374. onboarding,
  375. feedbackOnboardingCrashApi: appleFeedbackOnboarding,
  376. crashReportOnboarding: appleFeedbackOnboarding,
  377. customMetricsOnboarding: metricsOnboarding,
  378. };
  379. export default docs;