123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- 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 {getUploadSourceMapsStep} from 'sentry/components/onboarding/gettingStartedDoc/utils';
- import {
- getCrashReportJavaScriptInstallStep,
- getCrashReportModalConfigDescription,
- getCrashReportModalIntroduction,
- } from 'sentry/components/onboarding/gettingStartedDoc/utils/feedbackOnboarding';
- import {t, tct} from 'sentry/locale';
- import {getInstallConfig} from 'sentry/utils/gettingStartedDocs/node';
- type Params = DocsParams;
- const getSdkConfigureSnippetToml = () => `
- compatibility_flags = ["nodejs_compat"]
- # compatibility_flags = ["nodejs_als"]
- `;
- const getSdkConfigureSnippetJson = () => `
- {
- "compatibility_flags": [
- "nodejs_compat"
- ],
- "compatibility_date": "2024-09-23"
- }`;
- const getSdkSetupSnippet = (params: Params) => `
- import * as Sentry from "@sentry/cloudflare";
- export default Sentry.withSentry(
- env => ({
- dsn: "${params.dsn.public}",
- // Set tracesSampleRate to 1.0 to capture 100% of spans for tracing.
- // Learn more at
- // https://docs.sentry.io/platforms/javascript/configuration/options/#traces-sample-rate
- tracesSampleRate: 1.0,
- }),
- {
- async fetch(request, env, ctx) {
- return new Response('Hello World!');
- },
- } satisfies ExportedHandler<Env>,
- );`;
- const getVerifySnippet = () => `
- setTimeout(() => {
- throw new Error();
- });`;
- const onboarding: OnboardingConfig = {
- introduction: () =>
- t(
- 'In this quick guide you’ll set up and configure the Sentry Cloudflare SDK for the use in your Cloudflare Workers application.'
- ),
- install: params => [
- {
- type: StepType.INSTALL,
- description: t('Add the Sentry Cloudflare SDK as a dependency:'),
- configurations: getInstallConfig(params, {
- basePackage: '@sentry/cloudflare',
- }),
- },
- ],
- configure: params => [
- {
- type: StepType.CONFIGURE,
- description: t(
- "Configuration should happen as early as possible in your application's lifecycle."
- ),
- configurations: [
- {
- description: tct(
- "To use the SDK, you'll need to set either the [code:nodejs_compat] or [code:nodejs_als] compatibility flags in your [code:wrangler.json]/[code:wrangler.toml]. This is because the SDK needs access to the [code:AsyncLocalStorage] API to work correctly.",
- {
- code: <code />,
- }
- ),
- code: [
- {
- label: 'JSON',
- value: 'json',
- language: 'json',
- filename: 'wrangler.json',
- code: getSdkConfigureSnippetJson(),
- },
- {
- label: 'Toml',
- value: 'toml',
- language: 'toml',
- filename: 'wrangler.toml',
- code: getSdkConfigureSnippetToml(),
- },
- ],
- },
- {
- description: tct(
- 'In order to initialize the SDK, wrap your handler with the [code:withSentry] function. Note that you can turn off almost all side effects using the respective options.',
- {
- code: <code />,
- guideLink: (
- <ExternalLink href="https://developers.cloudflare.com/pages/functions/middleware/" />
- ),
- }
- ),
- code: [
- {
- label: 'TypeScript',
- value: 'typescript',
- language: 'typescript',
- code: getSdkSetupSnippet(params),
- },
- ],
- },
- ],
- },
- getUploadSourceMapsStep({
- guideLink:
- 'https://docs.sentry.io/platforms/javascript/guides/cloudflare/sourcemaps/',
- ...params,
- }),
- ],
- verify: () => [
- {
- type: StepType.VERIFY,
- description: t(
- "This snippet contains an intentional error and can be used as a test to make sure that everything's working as expected."
- ),
- configurations: [
- {
- language: 'javascript',
- code: getVerifySnippet(),
- },
- ],
- },
- ],
- };
- const crashReportOnboarding: OnboardingConfig = {
- introduction: () => getCrashReportModalIntroduction(),
- install: (params: Params) => getCrashReportJavaScriptInstallStep(params),
- configure: () => [
- {
- type: StepType.CONFIGURE,
- description: getCrashReportModalConfigDescription({
- link: 'https://docs.sentry.io/platforms/javascript/guides/cloudflare/user-feedback/configuration/#crash-report-modal',
- }),
- },
- ],
- verify: () => [],
- nextSteps: () => [],
- };
- const docs: Docs = {
- onboarding,
- crashReportOnboarding,
- };
- export default docs;
|