Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(onboarding): add cloudflare onboarding #83701

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@
"moment-timezone": "0.5.44",
"papaparse": "^5.3.2",
"peggy": "^4.1.1",
"platformicons": "^7.0.1",
"platformicons": "^7.0.4",
"po-catalog-loader": "2.1.0",
"prettier": "3.3.2",
"prismjs": "^1.29.0",
Expand Down
4 changes: 2 additions & 2 deletions src/sentry/models/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@
"apple-macos",
"bun",
"capacitor",
"cloudflare-pages",
"cloudflare-workers",
"cordova",
"dart",
"deno",
Expand Down Expand Up @@ -119,6 +117,8 @@
"node",
"node-awslambda",
"node-azurefunctions",
"node-cloudflare-pages",
"node-cloudflare-workers",
"node-connect",
"node-express",
"node-fastify",
Expand Down
7 changes: 4 additions & 3 deletions src/sentry/utils/platform_categories.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@
# When changing this file, make sure to keep sentry/static/app/data/platformCategories.tsx in sync.
BACKEND = {
"bun",
"cloudflare-pages",
"cloudflare-workers",
"deno",
"dotnet",
"dotnet-aspnet",
Expand All @@ -78,6 +76,8 @@
"kotlin",
"native",
"node",
"node-cloudflare-pages",
"node-cloudflare-workers",
constantinius marked this conversation as resolved.
Show resolved Hide resolved
"node-connect",
"node-express",
"node-fastify",
Expand Down Expand Up @@ -121,10 +121,11 @@
SERVERLESS = {
"dotnet-awslambda",
"dotnet-gcpfunctions",
"cloudflare-workers",
"node-awslambda",
"node-azurefunctions",
"node-gcpfunctions",
"node-cloudflare-pages",
"node-cloudflare-workers",
"python-awslambda",
"python-azurefunctions",
"python-gcpfunctions",
Expand Down
4 changes: 4 additions & 0 deletions static/app/data/platformCategories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ export const backend: PlatformKey[] = [
'node-express',
'node-koa',
'node-connect',
'node-cloudflare-pages',
'node-cloudflare-workers',
'perl',
'php',
'php-laravel',
Expand Down Expand Up @@ -127,6 +129,8 @@ export const serverless: PlatformKey[] = [
'node-awslambda',
'node-azurefunctions',
'node-gcpfunctions',
'node-cloudflare-pages',
'node-cloudflare-workers',
'python-awslambda',
'python-azurefunctions',
'python-gcpfunctions',
Expand Down
4 changes: 4 additions & 0 deletions static/app/data/platformPickerCategories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ const server: Set<PlatformKey> = new Set([
'kotlin',
'native',
'node',
'node-cloudflare-pages',
'node-cloudflare-workers',
'node-connect',
'node-express',
'node-fastify',
Expand Down Expand Up @@ -144,6 +146,8 @@ const serverless: Set<PlatformKey> = new Set([
'node-awslambda',
'node-azurefunctions',
'node-gcpfunctions',
'node-cloudflare-pages',
'node-cloudflare-workers',
'python-awslambda',
'python-gcpfunctions',
'python-serverless',
Expand Down
14 changes: 14 additions & 0 deletions static/app/data/platforms.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,20 @@ export const platforms: PlatformIntegration[] = [
language: 'node',
link: 'https://docs.sentry.io/platforms/javascript/guides/azure-functions/',
},
{
id: 'node-cloudflare-pages',
name: 'Cloudflare Pages',
type: 'framework',
language: 'node',
link: 'https://docs.sentry.io/platforms/javascript/guides/cloudflare/',
},
{
id: 'node-cloudflare-workers',
name: 'Cloudflare Workers',
type: 'framework',
language: 'node',
link: 'https://docs.sentry.io/platforms/javascript/guides/cloudflare/',
},
{
id: 'node-connect',
name: 'Connect',
Expand Down
40 changes: 40 additions & 0 deletions static/app/gettingStartedDocs/node/cloudflare-pages.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import {renderWithOnboardingLayout} from 'sentry-test/onboarding/renderWithOnboardingLayout';
import {screen} from 'sentry-test/reactTestingLibrary';
import {textWithMarkupMatcher} from 'sentry-test/utils';

import {ProductSolution} from 'sentry/components/onboarding/gettingStartedDoc/types';

import docs from './cloudflare-pages';

describe('express onboarding docs', function () {
it('renders onboarding docs correctly', () => {
renderWithOnboardingLayout(docs);

// Renders main headings
expect(screen.getByRole('heading', {name: 'Install'})).toBeInTheDocument();
expect(screen.getByRole('heading', {name: 'Configure SDK'})).toBeInTheDocument();
expect(screen.getByRole('heading', {name: 'Upload Source Maps'})).toBeInTheDocument();

// Includes import statement
const allMatches = screen.getAllByText(
textWithMarkupMatcher(/import \* as Sentry from "@sentry\/cloudflare"/)
);
allMatches.forEach(match => {
expect(match).toBeInTheDocument();
});
});

it('displays sample rates by default', () => {
renderWithOnboardingLayout(docs, {
selectedProducts: [
ProductSolution.ERROR_MONITORING,
ProductSolution.PERFORMANCE_MONITORING,
ProductSolution.PROFILING,
],
});

expect(
screen.getByText(textWithMarkupMatcher(/tracesSampleRate/))
).toBeInTheDocument();
});
});
161 changes: 161 additions & 0 deletions static/app/gettingStartedDocs/node/cloudflare-pages.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
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 const onRequest = [
// Make sure Sentry is the first middleware
Sentry.sentryPagesPlugin((context) => ({
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,
})),
// Add more middlewares here
];`;

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 Pages 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.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(
'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.',
{
code: <code />,
guideLink: (
<ExternalLink href="https://developers.cloudflare.com/pages/functions/middleware/" />
),
}
),
code: [
{
label: 'JavaScript',
value: 'javascript',
language: 'javascript',
filename: 'functions/_middleware.js',
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;
53 changes: 53 additions & 0 deletions static/app/gettingStartedDocs/node/cloudflare-workers.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import {renderWithOnboardingLayout} from 'sentry-test/onboarding/renderWithOnboardingLayout';
import {screen} from 'sentry-test/reactTestingLibrary';
import {textWithMarkupMatcher} from 'sentry-test/utils';

import {ProductSolution} from 'sentry/components/onboarding/gettingStartedDoc/types';

import docs from './cloudflare-workers';

describe('express onboarding docs', function () {
it('renders onboarding docs correctly', () => {
renderWithOnboardingLayout(docs);

// Renders main headings
expect(screen.getByRole('heading', {name: 'Install'})).toBeInTheDocument();
expect(screen.getByRole('heading', {name: 'Configure SDK'})).toBeInTheDocument();
expect(screen.getByRole('heading', {name: 'Upload Source Maps'})).toBeInTheDocument();

// Includes import statement
const allMatches = screen.getAllByText(
textWithMarkupMatcher(/import \* as Sentry from "@sentry\/cloudflare"/)
);
allMatches.forEach(match => {
expect(match).toBeInTheDocument();
});
});

it('displays sample rates by default', () => {
renderWithOnboardingLayout(docs, {
selectedProducts: [
ProductSolution.ERROR_MONITORING,
ProductSolution.PERFORMANCE_MONITORING,
ProductSolution.PROFILING,
],
});

expect(
screen.getByText(textWithMarkupMatcher(/tracesSampleRate/))
).toBeInTheDocument();
});

it('enables performance setting the tracesSampleRate to 1', () => {
renderWithOnboardingLayout(docs, {
selectedProducts: [
ProductSolution.ERROR_MONITORING,
ProductSolution.PERFORMANCE_MONITORING,
],
});

expect(
screen.getByText(textWithMarkupMatcher(/tracesSampleRate: 1\.0/))
).toBeInTheDocument();
});
});
Loading
Loading