apple-macos.tsx 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. import ExternalLink from 'sentry/components/links/externalLink';
  2. import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  3. import type {
  4. Docs,
  5. DocsParams,
  6. OnboardingConfig,
  7. } from 'sentry/components/onboarding/gettingStartedDoc/types';
  8. import {t, tct} from 'sentry/locale';
  9. import {getPackageVersion} from 'sentry/utils/gettingStartedDocs/getPackageVersion';
  10. type Params = DocsParams;
  11. const getInstallSnippet = (params: Params) => `
  12. .package(url: "https://github.com/getsentry/sentry-cocoa", from: "${getPackageVersion(
  13. params,
  14. 'sentry.cocoa',
  15. '8.9.3'
  16. )}"),`;
  17. const getConfigurationSnippet = (params: Params) => `
  18. import Sentry
  19. // ....
  20. func application(_ application: UIApplication,
  21. didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
  22. SentrySDK.start { options in
  23. options.dsn = "${params.dsn}"
  24. options.debug = true // Enabled debug when first installing is always helpful
  25. // Set tracesSampleRate to 1.0 to capture 100% of transactions for performance monitoring.
  26. // We recommend adjusting this value in production.
  27. options.tracesSampleRate = 1.0
  28. }
  29. return true
  30. }`;
  31. const getConfigurationSnippetSwiftUi = (params: Params) => `
  32. import Sentry
  33. @main
  34. struct SwiftUIApp: App {
  35. init() {
  36. SentrySDK.start { options in
  37. options.dsn = "${params.dsn}"
  38. options.debug = true // Enabled debug when first installing is always helpful
  39. // Set tracesSampleRate to 1.0 to capture 100% of transactions for performance monitoring.
  40. // We recommend adjusting this value in production.
  41. options.tracesSampleRate = 1.0
  42. }
  43. }
  44. }`;
  45. const getVerifySnippet = () => `
  46. let button = UIButton(type: .roundedRect)
  47. button.frame = CGRect(x: 20, y: 50, width: 100, height: 30)
  48. button.setTitle("Break the world", for: [])
  49. button.addTarget(self, action: #selector(self.breakTheWorld(_:)), for: .touchUpInside)
  50. view.addSubview(button)
  51. @IBAction func breakTheWorld(_ sender: AnyObject) {
  52. fatalError("Break the world")
  53. }`;
  54. const onboarding: OnboardingConfig = {
  55. install: params => [
  56. {
  57. type: StepType.INSTALL,
  58. description: (
  59. <p>
  60. {tct(
  61. '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:',
  62. {
  63. alternateMethods: (
  64. <ExternalLink href="https://docs.sentry.io/platforms/apple/install/" />
  65. ),
  66. addPackage: <strong />,
  67. }
  68. )}
  69. </p>
  70. ),
  71. configurations: [
  72. {
  73. language: 'text',
  74. code: `https://github.com/getsentry/sentry-cocoa.git`,
  75. },
  76. {
  77. description: (
  78. <p>
  79. {tct(
  80. 'Alternatively, when your project uses a [packageSwift: Package.swift] file to manage dependencies, you can specify the target with:',
  81. {
  82. packageSwift: <code />,
  83. }
  84. )}
  85. </p>
  86. ),
  87. language: 'swift',
  88. partialLoading: params.sourcePackageRegistries.isLoading,
  89. code: getInstallSnippet(params),
  90. },
  91. ],
  92. },
  93. ],
  94. configure: params => [
  95. {
  96. type: StepType.CONFIGURE,
  97. description: (
  98. <p>
  99. {tct(
  100. 'Make sure you initialize the SDK as soon as possible in your application lifecycle e.g. in your AppDelegate [appDelegate: application:didFinishLaunchingWithOptions] method:',
  101. {
  102. appDelegate: <code />,
  103. }
  104. )}
  105. </p>
  106. ),
  107. configurations: [
  108. {
  109. language: 'swift',
  110. code: getConfigurationSnippet(params),
  111. },
  112. {
  113. description: (
  114. <p>
  115. {tct(
  116. "When using SwiftUI and your app doesn't implement an app delegate, initialize the SDK within the [initializer: App conformer's initializer]:",
  117. {
  118. initializer: (
  119. <ExternalLink href="https://developer.apple.com/documentation/swiftui/app/main()" />
  120. ),
  121. }
  122. )}
  123. </p>
  124. ),
  125. language: 'swift',
  126. code: getConfigurationSnippetSwiftUi(params),
  127. },
  128. ],
  129. },
  130. ],
  131. verify: () => [
  132. {
  133. type: StepType.VERIFY,
  134. description: (
  135. <p>
  136. {tct(
  137. '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].',
  138. {
  139. viewController: <code />,
  140. }
  141. )}
  142. </p>
  143. ),
  144. configurations: [
  145. {
  146. language: 'swift',
  147. code: getVerifySnippet(),
  148. },
  149. ],
  150. },
  151. ],
  152. nextSteps: () => [
  153. {
  154. id: 'cocoapods-carthage',
  155. name: t('CocoaPods/Carthage'),
  156. description: t(
  157. 'Learn about integrating Sentry into your project using CocoaPods or Carthage.'
  158. ),
  159. link: 'https://docs.sentry.io/platforms/apple/install/',
  160. },
  161. {
  162. id: 'debug-symbols',
  163. name: t('Debug Symbols'),
  164. description: t('Symbolicate and get readable stacktraces in your Sentry errors.'),
  165. link: 'https://docs.sentry.io/platforms/apple/dsym/',
  166. },
  167. {
  168. id: 'swiftui',
  169. name: t('SwiftUI'),
  170. description: t('Learn about our first class integration with SwiftUI.'),
  171. link: 'https://docs.sentry.io/platforms/apple/performance/instrumentation/swiftui-instrumentation/',
  172. },
  173. {
  174. id: 'profiling',
  175. name: t('Profiling'),
  176. description: t(
  177. 'Collect and analyze performance profiles from real user devices in production.'
  178. ),
  179. link: 'https://docs.sentry.io/platforms/apple/profiling/',
  180. },
  181. ],
  182. };
  183. const docs: Docs = {
  184. onboarding,
  185. };
  186. export default docs;