apple.tsx 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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. export const nextSteps = [
  151. {
  152. id: 'cocoapods-carthage',
  153. name: t('CocoaPods/Carthage'),
  154. description: t(
  155. 'Learn about integrating Sentry into your project using CocoaPods or Carthage.'
  156. ),
  157. link: 'https://docs.sentry.io/platforms/apple/install/',
  158. },
  159. {
  160. id: 'debug-symbols',
  161. name: t('Debug Symbols'),
  162. description: t('Symbolicate and get readable stacktraces in your Sentry errors.'),
  163. link: 'https://docs.sentry.io/platforms/apple/dsym/',
  164. },
  165. {
  166. id: 'swiftui',
  167. name: t('SwiftUI'),
  168. description: t('Learn about our first class integration with SwiftUI.'),
  169. link: 'https://docs.sentry.io/platforms/apple/performance/instrumentation/swiftui-instrumentation/',
  170. },
  171. {
  172. id: 'profiling',
  173. name: t('Profiling'),
  174. description: t(
  175. 'Collect and analyze performance profiles from real user devices in production.'
  176. ),
  177. link: 'https://docs.sentry.io/platforms/apple/profiling/',
  178. },
  179. ];
  180. // Configuration End
  181. export function GettingStartedWithApple({
  182. dsn,
  183. sourcePackageRegistries,
  184. ...props
  185. }: ModuleProps) {
  186. return (
  187. <Layout
  188. steps={steps({dsn, sourcePackageRegistries})}
  189. nextSteps={nextSteps}
  190. {...props}
  191. />
  192. );
  193. }
  194. export default GettingStartedWithApple;