apple-macos.tsx 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  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 {
  9. getCrashReportApiIntroduction,
  10. getCrashReportInstallDescription,
  11. } from 'sentry/components/onboarding/gettingStartedDoc/utils/feedbackOnboarding';
  12. import {t, tct} from 'sentry/locale';
  13. import {getPackageVersion} from 'sentry/utils/gettingStartedDocs/getPackageVersion';
  14. type Params = DocsParams;
  15. const getInstallSnippet = (params: Params) => `
  16. .package(url: "https://github.com/getsentry/sentry-cocoa", from: "${getPackageVersion(
  17. params,
  18. 'sentry.cocoa',
  19. '8.9.3'
  20. )}"),`;
  21. const getConfigurationSnippet = (params: Params) => `
  22. import Sentry
  23. // ....
  24. func application(_ application: UIApplication,
  25. didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
  26. SentrySDK.start { options in
  27. options.dsn = "${params.dsn}"
  28. options.debug = true // Enabled debug when first installing is always helpful
  29. // Set tracesSampleRate to 1.0 to capture 100% of transactions for performance monitoring.
  30. // We recommend adjusting this value in production.
  31. options.tracesSampleRate = 1.0
  32. }
  33. return true
  34. }`;
  35. const getConfigurationSnippetSwiftUi = (params: Params) => `
  36. import Sentry
  37. @main
  38. struct SwiftUIApp: App {
  39. init() {
  40. SentrySDK.start { options in
  41. options.dsn = "${params.dsn}"
  42. options.debug = true // Enabled debug when first installing is always helpful
  43. // Set tracesSampleRate to 1.0 to capture 100% of transactions for performance monitoring.
  44. // We recommend adjusting this value in production.
  45. options.tracesSampleRate = 1.0
  46. }
  47. }
  48. }`;
  49. const getVerifySnippet = () => `
  50. let button = UIButton(type: .roundedRect)
  51. button.frame = CGRect(x: 20, y: 50, width: 100, height: 30)
  52. button.setTitle("Break the world", for: [])
  53. button.addTarget(self, action: #selector(self.breakTheWorld(_:)), for: .touchUpInside)
  54. view.addSubview(button)
  55. @IBAction func breakTheWorld(_ sender: AnyObject) {
  56. fatalError("Break the world")
  57. }`;
  58. const onboarding: OnboardingConfig = {
  59. install: params => [
  60. {
  61. type: StepType.INSTALL,
  62. description: (
  63. <p>
  64. {tct(
  65. '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:',
  66. {
  67. alternateMethods: (
  68. <ExternalLink href="https://docs.sentry.io/platforms/apple/install/" />
  69. ),
  70. addPackage: <strong />,
  71. }
  72. )}
  73. </p>
  74. ),
  75. configurations: [
  76. {
  77. language: 'url',
  78. code: `https://github.com/getsentry/sentry-cocoa.git`,
  79. },
  80. {
  81. description: (
  82. <p>
  83. {tct(
  84. 'Alternatively, when your project uses a [packageSwift: Package.swift] file to manage dependencies, you can specify the target with:',
  85. {
  86. packageSwift: <code />,
  87. }
  88. )}
  89. </p>
  90. ),
  91. language: 'swift',
  92. partialLoading: params.sourcePackageRegistries.isLoading,
  93. code: getInstallSnippet(params),
  94. },
  95. ],
  96. },
  97. ],
  98. configure: params => [
  99. {
  100. type: StepType.CONFIGURE,
  101. description: (
  102. <p>
  103. {tct(
  104. 'Make sure you initialize the SDK as soon as possible in your application lifecycle e.g. in your AppDelegate [appDelegate: application:didFinishLaunchingWithOptions] method:',
  105. {
  106. appDelegate: <code />,
  107. }
  108. )}
  109. </p>
  110. ),
  111. configurations: [
  112. {
  113. language: 'swift',
  114. code: getConfigurationSnippet(params),
  115. },
  116. {
  117. description: (
  118. <p>
  119. {tct(
  120. "When using SwiftUI and your app doesn't implement an app delegate, initialize the SDK within the [initializer: App conformer's initializer]:",
  121. {
  122. initializer: (
  123. <ExternalLink href="https://developer.apple.com/documentation/swiftui/app/main()" />
  124. ),
  125. }
  126. )}
  127. </p>
  128. ),
  129. language: 'swift',
  130. code: getConfigurationSnippetSwiftUi(params),
  131. },
  132. ],
  133. },
  134. ],
  135. verify: () => [
  136. {
  137. type: StepType.VERIFY,
  138. description: (
  139. <p>
  140. {tct(
  141. '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].',
  142. {
  143. viewController: <code />,
  144. }
  145. )}
  146. </p>
  147. ),
  148. configurations: [
  149. {
  150. language: 'swift',
  151. code: getVerifySnippet(),
  152. },
  153. ],
  154. },
  155. ],
  156. nextSteps: () => [
  157. {
  158. id: 'cocoapods-carthage',
  159. name: t('CocoaPods/Carthage'),
  160. description: t(
  161. 'Learn about integrating Sentry into your project using CocoaPods or Carthage.'
  162. ),
  163. link: 'https://docs.sentry.io/platforms/apple/install/',
  164. },
  165. {
  166. id: 'debug-symbols',
  167. name: t('Debug Symbols'),
  168. description: t('Symbolicate and get readable stacktraces in your Sentry errors.'),
  169. link: 'https://docs.sentry.io/platforms/apple/dsym/',
  170. },
  171. {
  172. id: 'swiftui',
  173. name: t('SwiftUI'),
  174. description: t('Learn about our first class integration with SwiftUI.'),
  175. link: 'https://docs.sentry.io/platforms/apple/performance/instrumentation/swiftui-instrumentation/',
  176. },
  177. {
  178. id: 'profiling',
  179. name: t('Profiling'),
  180. description: t(
  181. 'Collect and analyze performance profiles from real user devices in production.'
  182. ),
  183. link: 'https://docs.sentry.io/platforms/apple/profiling/',
  184. },
  185. ],
  186. };
  187. export const appleFeedbackOnboarding: OnboardingConfig = {
  188. introduction: () => getCrashReportApiIntroduction(),
  189. install: (params: Params) => [
  190. {
  191. type: StepType.INSTALL,
  192. description: getCrashReportInstallDescription(),
  193. configurations: [
  194. {
  195. code: [
  196. {
  197. label: 'Swift',
  198. value: 'swift',
  199. language: 'swift',
  200. code: `import Sentry
  201. let eventId = SentrySDK.capture(message: "My message.")
  202. let userFeedback = UserFeedback(eventId: eventId)
  203. userFeedback.comments = "It broke."
  204. userFeedback.email = "john.doe@example.com"
  205. userFeedback.name = "John Doe"
  206. SentrySDK.capture(userFeedback: userFeedback)`,
  207. },
  208. {
  209. label: 'Objective-C',
  210. value: 'c',
  211. language: 'c',
  212. code: `@import Sentry;
  213. SentryId *eventId = [SentrySDK captureMessage:@"My message"];
  214. SentryUserFeedback *userFeedback = [[SentryUserFeedback alloc] initWithEventId:eventId];
  215. userFeedback.comments = @"It broke.";
  216. userFeedback.email = @"john.doe@example.com";
  217. userFeedback.name = @"John Doe";
  218. [SentrySDK captureUserFeedback:userFeedback];`,
  219. },
  220. ],
  221. },
  222. {
  223. description: tct(
  224. 'To capture user feedback regarding a crash, use the [code:SentryOptions.onCrashedLastRun] callback. This callback gets called shortly after the initialization of the SDK when the last program execution terminated with a crash. It is not guaranteed that this is called on the main thread.',
  225. {code: <code />}
  226. ),
  227. code: [
  228. {
  229. label: 'Swift',
  230. value: 'swift',
  231. language: 'swift',
  232. code: `import Sentry
  233. SentrySDK.start { options in
  234. options.dsn = "${params.dsn}"
  235. options.onCrashedLastRun = { event in
  236. // capture user feedback
  237. }
  238. }
  239. `,
  240. },
  241. {
  242. label: 'Objective-C',
  243. value: 'c',
  244. language: 'c',
  245. code: `@import Sentry;
  246. [SentrySDK startWithConfigureOptions:^(SentryOptions *options) {
  247. options.dsn = @"${params.dsn}";
  248. options.onCrashedLastRun = ^void(SentryEvent * _Nonnull event) {
  249. // capture user feedback
  250. };
  251. }];`,
  252. },
  253. ],
  254. },
  255. ],
  256. },
  257. ],
  258. configure: () => [],
  259. verify: () => [],
  260. nextSteps: () => [],
  261. };
  262. const docs: Docs = {
  263. onboarding,
  264. feedbackOnboardingCrashApi: appleFeedbackOnboarding,
  265. crashReportOnboarding: appleFeedbackOnboarding,
  266. };
  267. export default docs;