macos.tsx 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  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 applicationDidFinishLaunching(_ aNotification: Notification) {
  25. SentrySDK.start { options in
  26. options.dsn = "${params.dsn.public}"
  27. options.debug = true // Enabling debug when first installing is always helpful${
  28. params.isPerformanceSelected
  29. ? `
  30. // Set tracesSampleRate to 1.0 to capture 100% of transactions for tracing.
  31. // We recommend adjusting this value in production.
  32. options.tracesSampleRate = 1.0`
  33. : ''
  34. }${
  35. params.isProfilingSelected &&
  36. params.profilingOptions?.defaultProfilingMode !== 'continuous'
  37. ? `
  38. // Sample rate for profiling, applied on top of TracesSampleRate.
  39. // We recommend adjusting this value in production.
  40. options.profilesSampleRate = 1.0`
  41. : ''
  42. }
  43. }${
  44. params.isProfilingSelected &&
  45. params.profilingOptions?.defaultProfilingMode === 'continuous'
  46. ? `
  47. // Manually call startProfiler and stopProfiler
  48. // to profile the code in between
  49. SentrySDK.startProfiler()
  50. // this code will be profiled
  51. //
  52. // Calls to stopProfiler are optional - if you don't stop the profiler, it will keep profiling
  53. // your application until the process exits or stopProfiler is called.
  54. SentrySDK.stopProfiler()`
  55. : ''
  56. }
  57. return true
  58. }`;
  59. const getConfigurationSnippetSwiftUi = (params: Params) => `
  60. import Sentry
  61. @main
  62. struct SwiftUIApp: App {
  63. init() {
  64. SentrySDK.start { options in
  65. options.dsn = "${params.dsn.public}"
  66. options.debug = true // Enabling debug when first installing is always helpful${
  67. params.isPerformanceSelected
  68. ? `
  69. // Set tracesSampleRate to 1.0 to capture 100% of transactions for tracing.
  70. // We recommend adjusting this value in production.
  71. options.tracesSampleRate = 1.0`
  72. : ''
  73. }${
  74. params.isProfilingSelected &&
  75. params.profilingOptions?.defaultProfilingMode !== 'continuous'
  76. ? `
  77. // Sample rate for profiling, applied on top of TracesSampleRate.
  78. // We recommend adjusting this value in production.
  79. options.profilesSampleRate = 1.0`
  80. : ''
  81. }
  82. }${
  83. params.isProfilingSelected &&
  84. params.profilingOptions?.defaultProfilingMode === 'continuous'
  85. ? `
  86. // Manually call start_profiler and stop_profiler
  87. // to profile the code in between
  88. SentrySDK.startProfiler()
  89. // do some work here
  90. SentrySDK.stopProfiler()`
  91. : ''
  92. }
  93. }
  94. }`;
  95. const getVerifySnippet = () => `
  96. let button = UIButton(type: .roundedRect)
  97. button.frame = CGRect(x: 20, y: 50, width: 100, height: 30)
  98. button.setTitle("Break the world", for: [])
  99. button.addTarget(self, action: #selector(self.breakTheWorld(_:)), for: .touchUpInside)
  100. view.addSubview(button)
  101. @IBAction func breakTheWorld(_ sender: AnyObject) {
  102. fatalError("Break the world")
  103. }`;
  104. const onboarding: OnboardingConfig = {
  105. install: params => [
  106. {
  107. type: StepType.INSTALL,
  108. description: (
  109. <p>
  110. {tct(
  111. '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:',
  112. {
  113. alternateMethods: (
  114. <ExternalLink href="https://docs.sentry.io/platforms/apple/install/" />
  115. ),
  116. addPackage: <strong />,
  117. }
  118. )}
  119. </p>
  120. ),
  121. configurations: [
  122. {
  123. language: 'url',
  124. code: `https://github.com/getsentry/sentry-cocoa.git`,
  125. },
  126. {
  127. description: (
  128. <p>
  129. {tct(
  130. 'Alternatively, when your project uses a [packageSwift: Package.swift] file to manage dependencies, you can specify the target with:',
  131. {
  132. packageSwift: <code />,
  133. }
  134. )}
  135. </p>
  136. ),
  137. language: 'swift',
  138. partialLoading: params.sourcePackageRegistries.isLoading,
  139. code: getInstallSnippet(params),
  140. },
  141. ],
  142. },
  143. ],
  144. configure: params => [
  145. {
  146. type: StepType.CONFIGURE,
  147. description: (
  148. <p>
  149. {tct(
  150. 'Make sure you initialize the SDK as soon as possible in your application lifecycle e.g. in your [appDelegate:] method:',
  151. {
  152. appDelegate: (
  153. <code>
  154. - [NSAppDelegate applicationDidFinishLaunchingWithNotification:]
  155. </code>
  156. ),
  157. }
  158. )}
  159. </p>
  160. ),
  161. configurations: [
  162. {
  163. language: 'swift',
  164. code: getConfigurationSnippet(params),
  165. },
  166. {
  167. description: (
  168. <p>
  169. {tct(
  170. "When using SwiftUI and your app doesn't implement an app delegate, initialize the SDK within the [initializer: App conformer's initializer]:",
  171. {
  172. initializer: (
  173. <ExternalLink href="https://developer.apple.com/documentation/swiftui/app/main()" />
  174. ),
  175. }
  176. )}
  177. </p>
  178. ),
  179. language: 'swift',
  180. code: getConfigurationSnippetSwiftUi(params),
  181. },
  182. ],
  183. },
  184. ],
  185. verify: () => [
  186. {
  187. type: StepType.VERIFY,
  188. description: (
  189. <p>
  190. {tct(
  191. '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].',
  192. {
  193. viewController: <code />,
  194. }
  195. )}
  196. </p>
  197. ),
  198. configurations: [
  199. {
  200. language: 'swift',
  201. code: getVerifySnippet(),
  202. },
  203. ],
  204. },
  205. ],
  206. nextSteps: () => [
  207. {
  208. id: 'cocoapods-carthage',
  209. name: t('CocoaPods/Carthage'),
  210. description: t(
  211. 'Learn about integrating Sentry into your project using CocoaPods or Carthage.'
  212. ),
  213. link: 'https://docs.sentry.io/platforms/apple/install/',
  214. },
  215. {
  216. id: 'debug-symbols',
  217. name: t('Debug Symbols'),
  218. description: t('Symbolicate and get readable stacktraces in your Sentry errors.'),
  219. link: 'https://docs.sentry.io/platforms/apple/dsym/',
  220. },
  221. {
  222. id: 'swiftui',
  223. name: t('SwiftUI'),
  224. description: t('Learn about our first class integration with SwiftUI.'),
  225. link: 'https://docs.sentry.io/platforms/apple/tracing/instrumentation/swiftui-instrumentation/',
  226. },
  227. ],
  228. };
  229. export const appleFeedbackOnboarding: OnboardingConfig = {
  230. introduction: () => getCrashReportApiIntroduction(),
  231. install: (params: Params) => [
  232. {
  233. type: StepType.INSTALL,
  234. description: getCrashReportInstallDescription(),
  235. configurations: [
  236. {
  237. code: [
  238. {
  239. label: 'Swift',
  240. value: 'swift',
  241. language: 'swift',
  242. code: `import Sentry
  243. let eventId = SentrySDK.capture(message: "My message.")
  244. let userFeedback = UserFeedback(eventId: eventId)
  245. userFeedback.comments = "It broke."
  246. userFeedback.email = "john.doe@example.com"
  247. userFeedback.name = "John Doe"
  248. SentrySDK.capture(userFeedback: userFeedback)`,
  249. },
  250. {
  251. label: 'Objective-C',
  252. value: 'c',
  253. language: 'c',
  254. code: `@import Sentry;
  255. SentryId *eventId = [SentrySDK captureMessage:@"My message"];
  256. SentryUserFeedback *userFeedback = [[SentryUserFeedback alloc] initWithEventId:eventId];
  257. userFeedback.comments = @"It broke.";
  258. userFeedback.email = @"john.doe@example.com";
  259. userFeedback.name = @"John Doe";
  260. [SentrySDK captureUserFeedback:userFeedback];`,
  261. },
  262. ],
  263. },
  264. {
  265. description: tct(
  266. '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.',
  267. {code: <code />}
  268. ),
  269. code: [
  270. {
  271. label: 'Swift',
  272. value: 'swift',
  273. language: 'swift',
  274. code: `import Sentry
  275. SentrySDK.start { options in
  276. options.dsn = "${params.dsn.public}"
  277. options.onCrashedLastRun = { event in
  278. // capture user feedback
  279. }
  280. }
  281. `,
  282. },
  283. {
  284. label: 'Objective-C',
  285. value: 'c',
  286. language: 'c',
  287. code: `@import Sentry;
  288. [SentrySDK startWithConfigureOptions:^(SentryOptions *options) {
  289. options.dsn = @"${params.dsn.public}";
  290. options.onCrashedLastRun = ^void(SentryEvent * _Nonnull event) {
  291. // capture user feedback
  292. };
  293. }];`,
  294. },
  295. ],
  296. },
  297. ],
  298. },
  299. ],
  300. configure: () => [],
  301. verify: () => [],
  302. nextSteps: () => [],
  303. };
  304. const docs: Docs = {
  305. onboarding,
  306. feedbackOnboardingCrashApi: appleFeedbackOnboarding,
  307. crashReportOnboarding: appleFeedbackOnboarding,
  308. };
  309. export default docs;