apple-ios.tsx 13 KB

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