123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309 |
- import ExternalLink from 'sentry/components/links/externalLink';
- import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
- import type {
- Docs,
- DocsParams,
- OnboardingConfig,
- } from 'sentry/components/onboarding/gettingStartedDoc/types';
- import {
- getCrashReportApiIntroduction,
- getCrashReportInstallDescription,
- } from 'sentry/components/onboarding/gettingStartedDoc/utils/feedbackOnboarding';
- import {t, tct} from 'sentry/locale';
- import {getPackageVersion} from 'sentry/utils/gettingStartedDocs/getPackageVersion';
- type Params = DocsParams;
- const getInstallSnippet = (params: Params) => `
- .package(url: "https://github.com/getsentry/sentry-cocoa", from: "${getPackageVersion(
- params,
- 'sentry.cocoa',
- '8.9.3'
- )}"),`;
- const getConfigurationSnippet = (params: Params) => `
- import Sentry
- // ....
- func applicationDidFinishLaunching(_ aNotification: Notification) {
- SentrySDK.start { options in
- options.dsn = "${params.dsn.public}"
- options.debug = true // Enabling debug when first installing is always helpful${
- params.isPerformanceSelected
- ? `
- // Set tracesSampleRate to 1.0 to capture 100% of transactions for tracing.
- // We recommend adjusting this value in production.
- options.tracesSampleRate = 1.0`
- : ''
- }${
- params.isProfilingSelected
- ? `
- // Sample rate for profiling, applied on top of TracesSampleRate.
- // We recommend adjusting this value in production.
- options.profilesSampleRate = 1.0`
- : ''
- }
- }
- return true
- }`;
- const getConfigurationSnippetSwiftUi = (params: Params) => `
- import Sentry
- @main
- struct SwiftUIApp: App {
- init() {
- SentrySDK.start { options in
- options.dsn = "${params.dsn.public}"
- options.debug = true // Enabling debug when first installing is always helpful${
- params.isPerformanceSelected
- ? `
- // Set tracesSampleRate to 1.0 to capture 100% of transactions for tracing.
- // We recommend adjusting this value in production.
- options.tracesSampleRate = 1.0`
- : ''
- }${
- params.isProfilingSelected
- ? `
- // Sample rate for profiling, applied on top of TracesSampleRate.
- // We recommend adjusting this value in production.
- options.profilesSampleRate = 1.0`
- : ''
- }
- }
- }
- }`;
- const getVerifySnippet = () => `
- let button = UIButton(type: .roundedRect)
- button.frame = CGRect(x: 20, y: 50, width: 100, height: 30)
- button.setTitle("Break the world", for: [])
- button.addTarget(self, action: #selector(self.breakTheWorld(_:)), for: .touchUpInside)
- view.addSubview(button)
- @IBAction func breakTheWorld(_ sender: AnyObject) {
- fatalError("Break the world")
- }`;
- const onboarding: OnboardingConfig = {
- install: params => [
- {
- type: StepType.INSTALL,
- description: (
- <p>
- {tct(
- '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:',
- {
- alternateMethods: (
- <ExternalLink href="https://docs.sentry.io/platforms/apple/install/" />
- ),
- addPackage: <strong />,
- }
- )}
- </p>
- ),
- configurations: [
- {
- language: 'url',
- code: `https://github.com/getsentry/sentry-cocoa.git`,
- },
- {
- description: (
- <p>
- {tct(
- 'Alternatively, when your project uses a [packageSwift: Package.swift] file to manage dependencies, you can specify the target with:',
- {
- packageSwift: <code />,
- }
- )}
- </p>
- ),
- language: 'swift',
- partialLoading: params.sourcePackageRegistries.isLoading,
- code: getInstallSnippet(params),
- },
- ],
- },
- ],
- configure: params => [
- {
- type: StepType.CONFIGURE,
- description: (
- <p>
- {tct(
- 'Make sure you initialize the SDK as soon as possible in your application lifecycle e.g. in your [appDelegate:] method:',
- {
- appDelegate: (
- <code>
- - [NSAppDelegate applicationDidFinishLaunchingWithNotification:]
- </code>
- ),
- }
- )}
- </p>
- ),
- configurations: [
- {
- language: 'swift',
- code: getConfigurationSnippet(params),
- },
- {
- description: (
- <p>
- {tct(
- "When using SwiftUI and your app doesn't implement an app delegate, initialize the SDK within the [initializer: App conformer's initializer]:",
- {
- initializer: (
- <ExternalLink href="https://developer.apple.com/documentation/swiftui/app/main()" />
- ),
- }
- )}
- </p>
- ),
- language: 'swift',
- code: getConfigurationSnippetSwiftUi(params),
- },
- ],
- },
- ],
- verify: () => [
- {
- type: StepType.VERIFY,
- description: (
- <p>
- {tct(
- '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].',
- {
- viewController: <code />,
- }
- )}
- </p>
- ),
- configurations: [
- {
- language: 'swift',
- code: getVerifySnippet(),
- },
- ],
- },
- ],
- nextSteps: () => [
- {
- id: 'cocoapods-carthage',
- name: t('CocoaPods/Carthage'),
- description: t(
- 'Learn about integrating Sentry into your project using CocoaPods or Carthage.'
- ),
- link: 'https://docs.sentry.io/platforms/apple/install/',
- },
- {
- id: 'debug-symbols',
- name: t('Debug Symbols'),
- description: t('Symbolicate and get readable stacktraces in your Sentry errors.'),
- link: 'https://docs.sentry.io/platforms/apple/dsym/',
- },
- {
- id: 'swiftui',
- name: t('SwiftUI'),
- description: t('Learn about our first class integration with SwiftUI.'),
- link: 'https://docs.sentry.io/platforms/apple/tracing/instrumentation/swiftui-instrumentation/',
- },
- ],
- };
- export const appleFeedbackOnboarding: OnboardingConfig = {
- introduction: () => getCrashReportApiIntroduction(),
- install: (params: Params) => [
- {
- type: StepType.INSTALL,
- description: getCrashReportInstallDescription(),
- configurations: [
- {
- code: [
- {
- label: 'Swift',
- value: 'swift',
- language: 'swift',
- code: `import Sentry
- let eventId = SentrySDK.capture(message: "My message.")
- let userFeedback = UserFeedback(eventId: eventId)
- userFeedback.comments = "It broke."
- userFeedback.email = "john.doe@example.com"
- userFeedback.name = "John Doe"
- SentrySDK.capture(userFeedback: userFeedback)`,
- },
- {
- label: 'Objective-C',
- value: 'c',
- language: 'c',
- code: `@import Sentry;
- SentryId *eventId = [SentrySDK captureMessage:@"My message"];
- SentryUserFeedback *userFeedback = [[SentryUserFeedback alloc] initWithEventId:eventId];
- userFeedback.comments = @"It broke.";
- userFeedback.email = @"john.doe@example.com";
- userFeedback.name = @"John Doe";
- [SentrySDK captureUserFeedback:userFeedback];`,
- },
- ],
- },
- {
- description: tct(
- '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.',
- {code: <code />}
- ),
- code: [
- {
- label: 'Swift',
- value: 'swift',
- language: 'swift',
- code: `import Sentry
- SentrySDK.start { options in
- options.dsn = "${params.dsn.public}"
- options.onCrashedLastRun = { event in
- // capture user feedback
- }
- }
- `,
- },
- {
- label: 'Objective-C',
- value: 'c',
- language: 'c',
- code: `@import Sentry;
- [SentrySDK startWithConfigureOptions:^(SentryOptions *options) {
- options.dsn = @"${params.dsn.public}";
- options.onCrashedLastRun = ^void(SentryEvent * _Nonnull event) {
- // capture user feedback
- };
- }];`,
- },
- ],
- },
- ],
- },
- ],
- configure: () => [],
- verify: () => [],
- nextSteps: () => [],
- };
- const docs: Docs = {
- onboarding,
- feedbackOnboardingCrashApi: appleFeedbackOnboarding,
- crashReportOnboarding: appleFeedbackOnboarding,
- };
- export default docs;
|