apple-ios.tsx 7.9 KB

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