|
| 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 {getUploadSourceMapsStep} from 'sentry/components/onboarding/gettingStartedDoc/utils'; |
| 9 | +import { |
| 10 | + getCrashReportJavaScriptInstallStep, |
| 11 | + getCrashReportModalConfigDescription, |
| 12 | + getCrashReportModalIntroduction, |
| 13 | +} from 'sentry/components/onboarding/gettingStartedDoc/utils/feedbackOnboarding'; |
| 14 | +import {t, tct} from 'sentry/locale'; |
| 15 | +import {getInstallConfig} from 'sentry/utils/gettingStartedDocs/node'; |
| 16 | + |
| 17 | +type Params = DocsParams; |
| 18 | + |
| 19 | +const getSdkConfigureSnippetToml = () => ` |
| 20 | +compatibility_flags = ["nodejs_compat"] |
| 21 | +# compatibility_flags = ["nodejs_als"] |
| 22 | +`; |
| 23 | + |
| 24 | +const getSdkConfigureSnippetJson = () => ` |
| 25 | +{ |
| 26 | + "compatibility_flags": [ |
| 27 | + "nodejs_compat" |
| 28 | + ], |
| 29 | + "compatibility_date": "2024-09-23" |
| 30 | +}`; |
| 31 | + |
| 32 | +const getSdkSetupSnippet = (params: Params) => ` |
| 33 | +import * as Sentry from "@sentry/cloudflare"; |
| 34 | +
|
| 35 | +export const onRequest = [ |
| 36 | + // Make sure Sentry is the first middleware |
| 37 | + Sentry.sentryPagesPlugin((context) => ({ |
| 38 | + dsn: "${params.dsn.public}", |
| 39 | + // Set tracesSampleRate to 1.0 to capture 100% of spans for tracing. |
| 40 | + // Learn more at |
| 41 | + // https://docs.sentry.io/platforms/javascript/configuration/options/#traces-sample-rate |
| 42 | + tracesSampleRate: 1.0, |
| 43 | + })), |
| 44 | + // Add more middlewares here |
| 45 | +];`; |
| 46 | + |
| 47 | +const getVerifySnippet = () => ` |
| 48 | +setTimeout(() => { |
| 49 | + throw new Error(); |
| 50 | +});`; |
| 51 | + |
| 52 | +const onboarding: OnboardingConfig = { |
| 53 | + introduction: () => |
| 54 | + t( |
| 55 | + 'In this quick guide you’ll set up and configure the Sentry Cloudflare SDK for the use in your Cloudflare Pages application.' |
| 56 | + ), |
| 57 | + install: params => [ |
| 58 | + { |
| 59 | + type: StepType.INSTALL, |
| 60 | + description: t('Add the Sentry Cloudflare SDK as a dependency:'), |
| 61 | + configurations: getInstallConfig(params, { |
| 62 | + basePackage: '@sentry/cloudflare', |
| 63 | + }), |
| 64 | + }, |
| 65 | + ], |
| 66 | + configure: params => [ |
| 67 | + { |
| 68 | + type: StepType.CONFIGURE, |
| 69 | + description: t( |
| 70 | + "Configuration should happen as early as possible in your application's lifecycle." |
| 71 | + ), |
| 72 | + configurations: [ |
| 73 | + { |
| 74 | + description: tct( |
| 75 | + "To use the SDK, you'll need to set either the [code:nodejs_compat] or [code:nodejs_als] compatibility flags in your [code:wrangler.toml]. This is because the SDK needs access to the [code:AsyncLocalStorage] API to work correctly.", |
| 76 | + { |
| 77 | + code: <code />, |
| 78 | + } |
| 79 | + ), |
| 80 | + code: [ |
| 81 | + { |
| 82 | + label: 'JSON', |
| 83 | + value: 'json', |
| 84 | + language: 'json', |
| 85 | + filename: 'wrangler.json', |
| 86 | + code: getSdkConfigureSnippetJson(), |
| 87 | + }, |
| 88 | + { |
| 89 | + label: 'Toml', |
| 90 | + value: 'toml', |
| 91 | + language: 'toml', |
| 92 | + filename: 'wrangler.toml', |
| 93 | + code: getSdkConfigureSnippetToml(), |
| 94 | + }, |
| 95 | + ], |
| 96 | + }, |
| 97 | + { |
| 98 | + description: tct( |
| 99 | + 'Add the [code:sentryPagesPlugin] as [guideLink:middleware to your Cloudflare Pages application]. We recommend adding a [code:functions/_middleware.js] for the middleware setup so that Sentry is initialized for your entire app.', |
| 100 | + { |
| 101 | + code: <code />, |
| 102 | + guideLink: ( |
| 103 | + <ExternalLink href="https://developers.cloudflare.com/pages/functions/middleware/" /> |
| 104 | + ), |
| 105 | + } |
| 106 | + ), |
| 107 | + code: [ |
| 108 | + { |
| 109 | + label: 'JavaScript', |
| 110 | + value: 'javascript', |
| 111 | + language: 'javascript', |
| 112 | + filename: 'functions/_middleware.js', |
| 113 | + code: getSdkSetupSnippet(params), |
| 114 | + }, |
| 115 | + ], |
| 116 | + }, |
| 117 | + ], |
| 118 | + }, |
| 119 | + getUploadSourceMapsStep({ |
| 120 | + guideLink: |
| 121 | + 'https://docs.sentry.io/platforms/javascript/guides/cloudflare/sourcemaps/', |
| 122 | + ...params, |
| 123 | + }), |
| 124 | + ], |
| 125 | + verify: () => [ |
| 126 | + { |
| 127 | + type: StepType.VERIFY, |
| 128 | + description: t( |
| 129 | + "This snippet contains an intentional error and can be used as a test to make sure that everything's working as expected." |
| 130 | + ), |
| 131 | + configurations: [ |
| 132 | + { |
| 133 | + language: 'javascript', |
| 134 | + code: getVerifySnippet(), |
| 135 | + }, |
| 136 | + ], |
| 137 | + }, |
| 138 | + ], |
| 139 | +}; |
| 140 | + |
| 141 | +const crashReportOnboarding: OnboardingConfig = { |
| 142 | + introduction: () => getCrashReportModalIntroduction(), |
| 143 | + install: (params: Params) => getCrashReportJavaScriptInstallStep(params), |
| 144 | + configure: () => [ |
| 145 | + { |
| 146 | + type: StepType.CONFIGURE, |
| 147 | + description: getCrashReportModalConfigDescription({ |
| 148 | + link: 'https://docs.sentry.io/platforms/javascript/guides/cloudflare/user-feedback/configuration/#crash-report-modal', |
| 149 | + }), |
| 150 | + }, |
| 151 | + ], |
| 152 | + verify: () => [], |
| 153 | + nextSteps: () => [], |
| 154 | +}; |
| 155 | + |
| 156 | +const docs: Docs = { |
| 157 | + onboarding, |
| 158 | + crashReportOnboarding, |
| 159 | +}; |
| 160 | + |
| 161 | +export default docs; |
0 commit comments