apple-ios.tsx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  1. import {Fragment} from 'react';
  2. import ExternalLink from 'sentry/components/links/externalLink';
  3. import List from 'sentry/components/list/';
  4. import ListItem from 'sentry/components/list/listItem';
  5. import {Layout, LayoutProps} from 'sentry/components/onboarding/gettingStartedDoc/layout';
  6. import {ModuleProps} from 'sentry/components/onboarding/gettingStartedDoc/sdkDocumentation';
  7. import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  8. import {ProductSolution} from 'sentry/components/onboarding/productSelection';
  9. import {t, tct} from 'sentry/locale';
  10. interface StepsParams {
  11. dsn: string;
  12. hasPerformance: boolean;
  13. hasProfiling: boolean;
  14. sourcePackageRegistries?: ModuleProps['sourcePackageRegistries'];
  15. }
  16. // Configuration Start
  17. export const steps = ({
  18. dsn,
  19. hasPerformance,
  20. hasProfiling,
  21. }: StepsParams): LayoutProps['steps'] => [
  22. {
  23. title: t('Auto-Install'),
  24. description: (
  25. <p>
  26. {tct(
  27. 'Add Sentry automatically to your app with the [wizardLink:Sentry wizard] (call this inside your project directory).',
  28. {
  29. wizardLink: (
  30. <ExternalLink href="https://docs.sentry.io/platforms/apple/guides/ios/#install" />
  31. ),
  32. }
  33. )}
  34. </p>
  35. ),
  36. configurations: [
  37. {
  38. language: 'bash',
  39. code: `brew install getsentry/tools/sentry-wizard && sentry-wizard -i ios`,
  40. },
  41. {
  42. description: (
  43. <Fragment>
  44. {t('The Sentry wizard will automatically patch your application:')}
  45. <List symbol="bullet">
  46. <ListItem>
  47. {t('Install the Sentry SDK via Swift Package Manager or Cocoapods')}
  48. </ListItem>
  49. <ListItem>
  50. {tct(
  51. 'Update your [appDelegate: AppDelegate] or SwiftUI App Initializer with the default Sentry configuration and an example error',
  52. {
  53. appDelegate: <code />,
  54. }
  55. )}
  56. </ListItem>
  57. <ListItem>
  58. {tct(
  59. 'Add a new [phase: Upload Debug Symbols] phase to your [xcodebuild: xcodebuild] build script',
  60. {
  61. phase: <code />,
  62. xcodebuild: <code />,
  63. }
  64. )}
  65. </ListItem>
  66. <ListItem>
  67. {tct(
  68. 'Create [sentryclirc: .sentryclirc] with an auth token to upload debug symbols (this file is automatically added to [gitignore: .gitignore])',
  69. {
  70. sentryclirc: <code />,
  71. gitignore: <code />,
  72. }
  73. )}
  74. </ListItem>
  75. <ListItem>
  76. {t(
  77. "When you're using Fastlane, it will add a Sentry lane for uploading debug symbols"
  78. )}
  79. </ListItem>
  80. </List>
  81. <p>
  82. {tct(
  83. 'Alternatively, you can also [manualSetupLink:set up the SDK manually]. [stepsBelow: You can skip the steps below when using the wizard].',
  84. {
  85. manualSetupLink: (
  86. <ExternalLink href="https://docs.sentry.io/platforms/apple/guides/ios/manual-setup/" />
  87. ),
  88. stepsBelow: <strong />,
  89. }
  90. )}
  91. </p>
  92. </Fragment>
  93. ),
  94. },
  95. ],
  96. },
  97. {
  98. title: t('Or Manually Install and Configure'),
  99. description: (
  100. <Fragment>
  101. <strong>{t('Install the Sentry SDK:')}</strong>
  102. <p>
  103. {tct(
  104. 'We recommend installing the SDK with Swift Package Manager (SPM), but we also support [alternateMethods: alternate installation methods]. To integrate Sentry into your Xcode project using SPM, open your App in Xcode and open [addPackage: File > Add Packages]. Then add the SDK by entering the Git repo url in the top right search field:',
  105. {
  106. alternateMethods: (
  107. <ExternalLink href="https://docs.sentry.io/platforms/apple/install/" />
  108. ),
  109. addPackage: <strong />,
  110. }
  111. )}
  112. </p>
  113. </Fragment>
  114. ),
  115. configurations: [
  116. {
  117. language: 'text',
  118. code: `
  119. https://github.com/getsentry/sentry-cocoa.git
  120. `,
  121. },
  122. {
  123. description: (
  124. <Fragment>
  125. <strong>{t('Configure the Sentry SDK:')}</strong>
  126. <p>
  127. {tct(
  128. 'Make sure you initialize the SDK as soon as possible in your application lifecycle e.g. in your AppDelegate [appDelegate: application:didFinishLaunchingWithOptions] method:',
  129. {
  130. appDelegate: <code />,
  131. }
  132. )}
  133. </p>
  134. </Fragment>
  135. ),
  136. language: 'swift',
  137. code: `
  138. import Sentry
  139. // ....
  140. func application(_ application: UIApplication,
  141. didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
  142. SentrySDK.start { options in
  143. options.dsn = "${dsn}"
  144. options.debug = true // Enabled debug when first installing is always helpful${
  145. hasPerformance
  146. ? `
  147. // Set tracesSampleRate to 1.0 to capture 100% of transactions for performance monitoring.
  148. // We recommend adjusting this value in production.
  149. options.tracesSampleRate = 1.0`
  150. : ''
  151. }${
  152. hasProfiling
  153. ? `
  154. // Set profilesSampleRate to 1.0 to profile 100% of sampled transactions.
  155. // We recommend adjusting this value in production
  156. options.profilesSampleRate = 1.0`
  157. : ''
  158. }
  159. }
  160. return true
  161. }
  162. `,
  163. },
  164. {
  165. description: (
  166. <p>
  167. {tct(
  168. "When using SwiftUI and your app doesn't implement an app delegate, initialize the SDK within the [initializer: App conformer's initializer]:",
  169. {
  170. initializer: (
  171. <ExternalLink href="https://developer.apple.com/documentation/swiftui/app/main()" />
  172. ),
  173. }
  174. )}
  175. </p>
  176. ),
  177. language: 'swift',
  178. code: `
  179. import Sentry
  180. @main
  181. struct SwiftUIApp: App {
  182. init() {
  183. SentrySDK.start { options in
  184. options.dsn = "${dsn}"
  185. options.debug = true // Enabled debug when first installing is always helpful${
  186. hasPerformance
  187. ? `
  188. // Set tracesSampleRate to 1.0 to capture 100% of transactions for performance monitoring.
  189. // We recommend adjusting this value in production.
  190. options.tracesSampleRate = 1.0`
  191. : ''
  192. }${
  193. hasProfiling
  194. ? `
  195. // Set profilesSampleRate to 1.0 to profile 100% of sampled transactions.
  196. // We recommend adjusting this value in production
  197. options.profilesSampleRate = 1.0`
  198. : ''
  199. }
  200. }
  201. }
  202. }
  203. `,
  204. },
  205. ],
  206. },
  207. {
  208. type: StepType.VERIFY,
  209. description: (
  210. <p>
  211. {tct(
  212. 'This snippet contains an intentional error you can use to test that errors are uploaded to Sentry correctly. You can add it to your main [viewController: ViewController].',
  213. {
  214. viewController: <code />,
  215. }
  216. )}
  217. </p>
  218. ),
  219. configurations: [
  220. {
  221. language: 'swift',
  222. code: `
  223. let button = UIButton(type: .roundedRect)
  224. button.frame = CGRect(x: 20, y: 50, width: 100, height: 30)
  225. button.setTitle("Break the world", for: [])
  226. button.addTarget(self, action: #selector(self.breakTheWorld(_:)), for: .touchUpInside)
  227. view.addSubview(button)
  228. @IBAction func breakTheWorld(_ sender: AnyObject) {
  229. fatalError("Break the world")
  230. }
  231. `,
  232. },
  233. ],
  234. },
  235. {
  236. title: t('Experimental Features'),
  237. description: (
  238. <p>
  239. {tct(
  240. '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].',
  241. {
  242. vh: (
  243. <ExternalLink href="https://docs.sentry.io/platforms/apple/guides/ios/enriching-events/viewhierarchy/" />
  244. ),
  245. ttfd: (
  246. <ExternalLink href="https://docs.sentry.io/platforms/apple/guides/ios/performance/instrumentation/automatic-instrumentation/#time-to-full-display" />
  247. ),
  248. metricKit: (
  249. <ExternalLink href="https://docs.sentry.io/platforms/apple/guides/watchos/configuration/metric-kit/" />
  250. ),
  251. prewarmedAppStart: (
  252. <ExternalLink href="https://docs.sentry.io/platforms/apple/performance/instrumentation/automatic-instrumentation/#prewarmed-app-start-tracing" />
  253. ),
  254. asyncStacktraces: (
  255. <ExternalLink href="https://docs.sentry.io/platforms/apple/guides/ios/#stitch-together-swift-concurrency-stack-traces" />
  256. ),
  257. gh: <ExternalLink href="https://github.com/getsentry/sentry-cocoa/issues" />,
  258. break: <br />,
  259. }
  260. )}
  261. </p>
  262. ),
  263. configurations: [
  264. {
  265. language: 'swift',
  266. code: `
  267. import Sentry
  268. SentrySDK.start { options in
  269. // ...
  270. // Enable all experimental features
  271. options.attachViewHierarchy = true
  272. options.enablePreWarmedAppStartTracing = true
  273. options.enableMetricKit = true
  274. options.enableTimeToFullDisplayTracing = true
  275. options.swiftAsyncStacktraces = true
  276. }
  277. `,
  278. },
  279. ],
  280. },
  281. ];
  282. export const nextSteps = [
  283. {
  284. id: 'cocoapods-carthage',
  285. name: t('CocoaPods/Carthage'),
  286. description: t(
  287. 'Learn about integrating Sentry into your project using CocoaPods or Carthage.'
  288. ),
  289. link: 'https://docs.sentry.io/platforms/apple/install/',
  290. },
  291. {
  292. id: 'debug-symbols',
  293. name: t('Debug Symbols'),
  294. description: t('Symbolicate and get readable stacktraces in your Sentry errors.'),
  295. link: 'https://docs.sentry.io/platforms/apple/dsym/',
  296. },
  297. {
  298. id: 'swiftui',
  299. name: t('SwiftUI'),
  300. description: t('Learn about our first class integration with SwiftUI.'),
  301. link: 'https://docs.sentry.io/platforms/apple/performance/instrumentation/swiftui-instrumentation/',
  302. },
  303. {
  304. id: 'profiling',
  305. name: t('Profiling'),
  306. description: t(
  307. 'Collect and analyze performance profiles from real user devices in production.'
  308. ),
  309. link: 'https://docs.sentry.io/platforms/apple/profiling/',
  310. },
  311. ];
  312. // Configuration End
  313. export function GettingStartedWithIos({
  314. dsn,
  315. sourcePackageRegistries,
  316. activeProductSelection = [],
  317. ...props
  318. }: ModuleProps) {
  319. const hasPerformance = activeProductSelection.includes(
  320. ProductSolution.PERFORMANCE_MONITORING
  321. );
  322. const hasProfiling = activeProductSelection.includes(ProductSolution.PROFILING);
  323. return (
  324. <Layout
  325. steps={steps({dsn, sourcePackageRegistries, hasPerformance, hasProfiling})}
  326. nextSteps={nextSteps}
  327. {...props}
  328. />
  329. );
  330. }
  331. export default GettingStartedWithIos;