apple-ios.tsx 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. import ExternalLink from 'sentry/components/links/externalLink';
  2. import {Layout, LayoutProps} from 'sentry/components/onboarding/gettingStartedDoc/layout';
  3. import {ModuleProps} from 'sentry/components/onboarding/gettingStartedDoc/sdkDocumentation';
  4. import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  5. import {ProductSolution} from 'sentry/components/onboarding/productSelection';
  6. import {t, tct} from 'sentry/locale';
  7. interface StepProps {
  8. dsn: string;
  9. hasPerformance: boolean;
  10. hasProfiling: boolean;
  11. sourcePackageRegistries?: ModuleProps['sourcePackageRegistries'];
  12. }
  13. // Configuration Start
  14. export const steps = ({
  15. dsn,
  16. sourcePackageRegistries,
  17. hasPerformance,
  18. hasProfiling,
  19. }: StepProps): LayoutProps['steps'] => [
  20. {
  21. type: StepType.INSTALL,
  22. description: (
  23. <p>
  24. {tct(
  25. '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:',
  26. {
  27. alternateMethods: (
  28. <ExternalLink href="https://docs.sentry.io/platforms/apple/install/" />
  29. ),
  30. addPackage: <strong />,
  31. }
  32. )}
  33. </p>
  34. ),
  35. configurations: [
  36. {
  37. language: 'text',
  38. code: `
  39. https://github.com/getsentry/sentry-cocoa.git
  40. `,
  41. },
  42. {
  43. description: (
  44. <p>
  45. {tct(
  46. 'Alternatively, when your project uses a [packageSwift: Package.swift] file to manage dependencies, you can specify the target with:',
  47. {
  48. packageSwift: <code />,
  49. }
  50. )}
  51. </p>
  52. ),
  53. language: 'swift',
  54. partialLoading: sourcePackageRegistries?.isLoading,
  55. code: `
  56. .package(url: "https://github.com/getsentry/sentry-cocoa", from: "${
  57. sourcePackageRegistries?.isLoading
  58. ? t('\u2026loading')
  59. : sourcePackageRegistries?.data?.['sentry.cocoa']?.version ?? '8.9.3'
  60. }"),
  61. `,
  62. },
  63. ],
  64. },
  65. {
  66. type: StepType.CONFIGURE,
  67. description: (
  68. <p>
  69. {tct(
  70. 'Make sure you initialize the SDK as soon as possible in your application lifecycle e.g. in your AppDelegate [appDelegate: application:didFinishLaunchingWithOptions] method:',
  71. {
  72. appDelegate: <code />,
  73. }
  74. )}
  75. </p>
  76. ),
  77. configurations: [
  78. {
  79. language: 'swift',
  80. code: `
  81. import Sentry
  82. // ....
  83. func application(_ application: UIApplication,
  84. didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
  85. SentrySDK.start { options in
  86. options.dsn = "${dsn}"
  87. options.debug = true // Enabled debug when first installing is always helpful${
  88. hasPerformance
  89. ? `
  90. // Set tracesSampleRate to 1.0 to capture 100% of transactions for performance monitoring.
  91. // We recommend adjusting this value in production.
  92. options.tracesSampleRate = 1.0`
  93. : ''
  94. }${
  95. hasProfiling
  96. ? `
  97. // Set profilesSampleRate to 1.0 to profile 100% of sampled transactions.
  98. // We recommend adjusting this value in production
  99. options.profilesSampleRate = 1.0`
  100. : ''
  101. }
  102. }
  103. return true
  104. }
  105. `,
  106. },
  107. {
  108. description: (
  109. <p>
  110. {tct(
  111. "When using SwiftUI and your app doesn't implement an app delegate, initialize the SDK within the [initializer: App conformer's initializer]:",
  112. {
  113. initializer: (
  114. <ExternalLink href="https://developer.apple.com/documentation/swiftui/app/main()" />
  115. ),
  116. }
  117. )}
  118. </p>
  119. ),
  120. language: 'swift',
  121. code: `
  122. import Sentry
  123. @main
  124. struct SwiftUIApp: App {
  125. init() {
  126. SentrySDK.start { options in
  127. options.dsn = "${dsn}"
  128. options.debug = true // Enabled debug when first installing is always helpful${
  129. hasPerformance
  130. ? `
  131. // Set tracesSampleRate to 1.0 to capture 100% of transactions for performance monitoring.
  132. // We recommend adjusting this value in production.
  133. options.tracesSampleRate = 1.0`
  134. : ''
  135. }${
  136. hasProfiling
  137. ? `
  138. // Set profilesSampleRate to 1.0 to profile 100% of sampled transactions.
  139. // We recommend adjusting this value in production
  140. options.profilesSampleRate = 1.0`
  141. : ''
  142. }
  143. }
  144. }
  145. }
  146. `,
  147. },
  148. ],
  149. },
  150. {
  151. type: StepType.VERIFY,
  152. description: (
  153. <p>
  154. {tct(
  155. '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].',
  156. {
  157. viewController: <code />,
  158. }
  159. )}
  160. </p>
  161. ),
  162. configurations: [
  163. {
  164. language: 'swift',
  165. code: `
  166. let button = UIButton(type: .roundedRect)
  167. button.frame = CGRect(x: 20, y: 50, width: 100, height: 30)
  168. button.setTitle("Break the world", for: [])
  169. button.addTarget(self, action: #selector(self.breakTheWorld(_:)), for: .touchUpInside)
  170. view.addSubview(button)
  171. @IBAction func breakTheWorld(_ sender: AnyObject) {
  172. fatalError("Break the world")
  173. }
  174. `,
  175. },
  176. ],
  177. },
  178. {
  179. title: t('Experimental Features'),
  180. description: (
  181. <p>
  182. {tct(
  183. '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].',
  184. {
  185. vh: (
  186. <ExternalLink href="https://docs.sentry.io/platforms/apple/guides/ios/enriching-events/viewhierarchy/" />
  187. ),
  188. ttfd: (
  189. <ExternalLink href="https://docs.sentry.io/platforms/apple/guides/ios/performance/instrumentation/automatic-instrumentation/#time-to-full-display" />
  190. ),
  191. metricKit: (
  192. <ExternalLink href="https://docs.sentry.io/platforms/apple/guides/watchos/configuration/metric-kit/" />
  193. ),
  194. prewarmedAppStart: (
  195. <ExternalLink href="https://docs.sentry.io/platforms/apple/performance/instrumentation/automatic-instrumentation/#prewarmed-app-start-tracing" />
  196. ),
  197. asyncStacktraces: (
  198. <ExternalLink href="https://docs.sentry.io/platforms/apple/guides/ios/#stitch-together-swift-concurrency-stack-traces" />
  199. ),
  200. gh: <ExternalLink href="https://github.com/getsentry/sentry-cocoa/issues" />,
  201. break: <br />,
  202. }
  203. )}
  204. </p>
  205. ),
  206. configurations: [
  207. {
  208. language: 'swift',
  209. code: `
  210. import Sentry
  211. SentrySDK.start { options in
  212. // ...
  213. // Enable all experimental features
  214. options.attachViewHierarchy = true
  215. options.enablePreWarmedAppStartTracing = true
  216. options.enableMetricKit = true
  217. options.enableTimeToFullDisplayTracing = true
  218. options.swiftAsyncStacktraces = true
  219. }
  220. `,
  221. },
  222. ],
  223. },
  224. ];
  225. export const nextSteps = [
  226. {
  227. id: 'cocoapods-carthage',
  228. name: t('CocoaPods/Carthage'),
  229. description: t(
  230. 'Learn about integrating Sentry into your project using CocoaPods or Carthage.'
  231. ),
  232. link: 'https://docs.sentry.io/platforms/apple/install/',
  233. },
  234. {
  235. id: 'debug-symbols',
  236. name: t('Debug Symbols'),
  237. description: t('Symbolicate and get readable stacktraces in your Sentry errors.'),
  238. link: 'https://docs.sentry.io/platforms/apple/dsym/',
  239. },
  240. {
  241. id: 'swiftui',
  242. name: t('SwiftUI'),
  243. description: t('Learn about our first class integration with SwiftUI.'),
  244. link: 'https://docs.sentry.io/platforms/apple/performance/instrumentation/swiftui-instrumentation/',
  245. },
  246. {
  247. id: 'profiling',
  248. name: t('Profiling'),
  249. description: t(
  250. 'Collect and analyze performance profiles from real user devices in production.'
  251. ),
  252. link: 'https://docs.sentry.io/platforms/apple/profiling/',
  253. },
  254. ];
  255. // Configuration End
  256. export function GettingStartedWithIos({
  257. dsn,
  258. sourcePackageRegistries,
  259. activeProductSelection = [],
  260. ...props
  261. }: ModuleProps) {
  262. const hasPerformance = activeProductSelection.includes(
  263. ProductSolution.PERFORMANCE_MONITORING
  264. );
  265. const hasProfiling = activeProductSelection.includes(ProductSolution.PROFILING);
  266. return (
  267. <Layout
  268. steps={steps({dsn, sourcePackageRegistries, hasPerformance, hasProfiling})}
  269. nextSteps={nextSteps}
  270. {...props}
  271. />
  272. );
  273. }
  274. export default GettingStartedWithIos;