From a5c05e467db6b5f7a794f243e8c53deca2802fb3 Mon Sep 17 00:00:00 2001 From: Charly Gomez Date: Wed, 12 Nov 2025 11:26:05 +0100 Subject: [PATCH 1/3] add cf onboarding --- .../node/cloudflare-pages/index.tsx | 2 ++ .../node/cloudflare-pages/metrics.tsx | 6 +++++ .../node/cloudflare-pages/onboarding.spec.tsx | 24 +++++++++++++++++++ .../node/cloudflare-pages/onboarding.tsx | 7 ++++++ .../node/cloudflare-workers/index.tsx | 2 ++ .../node/cloudflare-workers/metrics.tsx | 6 +++++ .../cloudflare-workers/onboarding.spec.tsx | 24 +++++++++++++++++++ .../node/cloudflare-workers/onboarding.tsx | 8 +++++++ .../gettingStartedDocs/node/node/utils.tsx | 20 ++-------------- 9 files changed, 81 insertions(+), 18 deletions(-) create mode 100644 static/app/gettingStartedDocs/node/cloudflare-pages/metrics.tsx create mode 100644 static/app/gettingStartedDocs/node/cloudflare-workers/metrics.tsx diff --git a/static/app/gettingStartedDocs/node/cloudflare-pages/index.tsx b/static/app/gettingStartedDocs/node/cloudflare-pages/index.tsx index 66bf7079d4e76b..381e4fa01640c1 100644 --- a/static/app/gettingStartedDocs/node/cloudflare-pages/index.tsx +++ b/static/app/gettingStartedDocs/node/cloudflare-pages/index.tsx @@ -4,6 +4,7 @@ import {agentMonitoring} from './agentMonitoring'; import {crashReport} from './crashReport'; import {logs} from './logs'; import {mcp} from './mcp'; +import {metrics} from './metrics'; import {onboarding} from './onboarding'; const docs: Docs = { @@ -12,6 +13,7 @@ const docs: Docs = { logsOnboarding: logs, agentMonitoringOnboarding: agentMonitoring, mcpOnboarding: mcp, + metricsOnboarding: metrics, }; export default docs; diff --git a/static/app/gettingStartedDocs/node/cloudflare-pages/metrics.tsx b/static/app/gettingStartedDocs/node/cloudflare-pages/metrics.tsx new file mode 100644 index 00000000000000..1b1c02ac27411e --- /dev/null +++ b/static/app/gettingStartedDocs/node/cloudflare-pages/metrics.tsx @@ -0,0 +1,6 @@ +import {getNodeMetricsOnboarding} from 'sentry/gettingStartedDocs/node/node/utils'; + +export const metrics = getNodeMetricsOnboarding({ + docsPlatform: 'cloudflare', + packageName: '@sentry/cloudflare', +}); diff --git a/static/app/gettingStartedDocs/node/cloudflare-pages/onboarding.spec.tsx b/static/app/gettingStartedDocs/node/cloudflare-pages/onboarding.spec.tsx index af8b91310bbf76..ca5805544d1f3c 100644 --- a/static/app/gettingStartedDocs/node/cloudflare-pages/onboarding.spec.tsx +++ b/static/app/gettingStartedDocs/node/cloudflare-pages/onboarding.spec.tsx @@ -105,4 +105,28 @@ describe('cloudflare-pages onboarding docs', () => { expect(screen.getByText('Cloudflare Features')).toBeInTheDocument(); }); + + it('displays metrics code in verify section when metrics are selected', () => { + renderWithOnboardingLayout(docs, { + selectedProducts: [ProductSolution.ERROR_MONITORING, ProductSolution.METRICS], + }); + + expect( + screen.getByText( + textWithMarkupMatcher(/Sentry\.metrics\.count\('test_counter', 1\)/) + ) + ).toBeInTheDocument(); + }); + + it('does not display metrics code in verify section when metrics are not selected', () => { + renderWithOnboardingLayout(docs, { + selectedProducts: [ProductSolution.ERROR_MONITORING], + }); + + expect( + screen.queryByText( + textWithMarkupMatcher(/Sentry\.metrics\.count\('test_counter', 1\)/) + ) + ).not.toBeInTheDocument(); + }); }); diff --git a/static/app/gettingStartedDocs/node/cloudflare-pages/onboarding.tsx b/static/app/gettingStartedDocs/node/cloudflare-pages/onboarding.tsx index 038d672d503f1f..806c3c4d48fb43 100644 --- a/static/app/gettingStartedDocs/node/cloudflare-pages/onboarding.tsx +++ b/static/app/gettingStartedDocs/node/cloudflare-pages/onboarding.tsx @@ -61,6 +61,13 @@ export function onRequest(context) {${ action: 'test_error_function', });` : '' +}${ + params.isMetricsSelected + ? ` +// Send a test metric before throwing the error +Sentry.metrics.count('test_counter', 1); +` + : '' } throw new Error(); }`; diff --git a/static/app/gettingStartedDocs/node/cloudflare-workers/index.tsx b/static/app/gettingStartedDocs/node/cloudflare-workers/index.tsx index 66bf7079d4e76b..381e4fa01640c1 100644 --- a/static/app/gettingStartedDocs/node/cloudflare-workers/index.tsx +++ b/static/app/gettingStartedDocs/node/cloudflare-workers/index.tsx @@ -4,6 +4,7 @@ import {agentMonitoring} from './agentMonitoring'; import {crashReport} from './crashReport'; import {logs} from './logs'; import {mcp} from './mcp'; +import {metrics} from './metrics'; import {onboarding} from './onboarding'; const docs: Docs = { @@ -12,6 +13,7 @@ const docs: Docs = { logsOnboarding: logs, agentMonitoringOnboarding: agentMonitoring, mcpOnboarding: mcp, + metricsOnboarding: metrics, }; export default docs; diff --git a/static/app/gettingStartedDocs/node/cloudflare-workers/metrics.tsx b/static/app/gettingStartedDocs/node/cloudflare-workers/metrics.tsx new file mode 100644 index 00000000000000..1b1c02ac27411e --- /dev/null +++ b/static/app/gettingStartedDocs/node/cloudflare-workers/metrics.tsx @@ -0,0 +1,6 @@ +import {getNodeMetricsOnboarding} from 'sentry/gettingStartedDocs/node/node/utils'; + +export const metrics = getNodeMetricsOnboarding({ + docsPlatform: 'cloudflare', + packageName: '@sentry/cloudflare', +}); diff --git a/static/app/gettingStartedDocs/node/cloudflare-workers/onboarding.spec.tsx b/static/app/gettingStartedDocs/node/cloudflare-workers/onboarding.spec.tsx index fe5226c849a99b..dc815d35b8713c 100644 --- a/static/app/gettingStartedDocs/node/cloudflare-workers/onboarding.spec.tsx +++ b/static/app/gettingStartedDocs/node/cloudflare-workers/onboarding.spec.tsx @@ -105,4 +105,28 @@ describe('cloudflare-workers onboarding docs', () => { expect(screen.getByText('Cloudflare Features')).toBeInTheDocument(); }); + + it('displays metrics code in verify section when metrics are selected', () => { + renderWithOnboardingLayout(docs, { + selectedProducts: [ProductSolution.ERROR_MONITORING, ProductSolution.METRICS], + }); + + expect( + screen.getByText( + textWithMarkupMatcher(/Sentry\.metrics\.count\('test_counter', 1\)/) + ) + ).toBeInTheDocument(); + }); + + it('does not display metrics code in verify section when metrics are not selected', () => { + renderWithOnboardingLayout(docs, { + selectedProducts: [ProductSolution.ERROR_MONITORING], + }); + + expect( + screen.queryByText( + textWithMarkupMatcher(/Sentry\.metrics\.count\('test_counter', 1\)/) + ) + ).not.toBeInTheDocument(); + }); }); diff --git a/static/app/gettingStartedDocs/node/cloudflare-workers/onboarding.tsx b/static/app/gettingStartedDocs/node/cloudflare-workers/onboarding.tsx index 9ee2faa7f3bf30..95692c49a02774 100644 --- a/static/app/gettingStartedDocs/node/cloudflare-workers/onboarding.tsx +++ b/static/app/gettingStartedDocs/node/cloudflare-workers/onboarding.tsx @@ -63,6 +63,14 @@ Sentry.logger.info('User triggered test error', { });` : '' } +${ + params.isMetricsSelected + ? ` +// Send a test metric before throwing the error +Sentry.metrics.count('test_counter', 1); +` + : '' +} setTimeout(() => { throw new Error(); });`; diff --git a/static/app/gettingStartedDocs/node/node/utils.tsx b/static/app/gettingStartedDocs/node/node/utils.tsx index f7810d9b78a4ef..cf105ecee0250a 100644 --- a/static/app/gettingStartedDocs/node/node/utils.tsx +++ b/static/app/gettingStartedDocs/node/node/utils.tsx @@ -892,33 +892,17 @@ export const getNodeMetricsOnboarding = < ], }, ], - configure: (params: DocsParams) => [ + configure: () => [ { type: StepType.CONFIGURE, content: [ { type: 'text', text: tct( - 'Metrics are automatically enabled in your [code:Sentry.init()] configuration. You can emit metrics using the [code:Sentry.metrics] API.', + 'Metrics are automatically enabled after Sentry is initialized. You can emit metrics using the [code:Sentry.metrics] API.', {code: } ), }, - { - type: 'code', - language: 'javascript', - code: ` -const Sentry = require("${packageName}"); - -Sentry.init({ - dsn: "${params.dsn.public}", -}); - -// Emit custom metrics -Sentry.metrics.count('button_click', 1); -Sentry.metrics.gauge('page_load_time', 150); -Sentry.metrics.distribution('response_time', 200); -`, - }, { type: 'text', text: tct( From 069e897a6e62835fc9ece8ebfa2b0ec3bfe8a70f Mon Sep 17 00:00:00 2001 From: Charly Gomez Date: Wed, 12 Nov 2025 12:47:27 +0100 Subject: [PATCH 2/3] move utils to metrics file --- .../node/cloudflare-pages/metrics.tsx | 2 +- .../node/cloudflare-workers/metrics.tsx | 2 +- .../node/connect/metrics.tsx | 2 +- .../node/express/metrics.tsx | 2 +- .../node/fastify/metrics.tsx | 2 +- .../gettingStartedDocs/node/koa/metrics.tsx | 2 +- .../node/nestjs/metrics.tsx | 2 +- .../gettingStartedDocs/node/node/metrics.tsx | 104 +++++++++++++++++- .../gettingStartedDocs/node/node/utils.tsx | 93 ---------------- 9 files changed, 110 insertions(+), 101 deletions(-) diff --git a/static/app/gettingStartedDocs/node/cloudflare-pages/metrics.tsx b/static/app/gettingStartedDocs/node/cloudflare-pages/metrics.tsx index 1b1c02ac27411e..d7902e7ee03f31 100644 --- a/static/app/gettingStartedDocs/node/cloudflare-pages/metrics.tsx +++ b/static/app/gettingStartedDocs/node/cloudflare-pages/metrics.tsx @@ -1,4 +1,4 @@ -import {getNodeMetricsOnboarding} from 'sentry/gettingStartedDocs/node/node/utils'; +import {getNodeMetricsOnboarding} from 'sentry/gettingStartedDocs/node/node/metrics'; export const metrics = getNodeMetricsOnboarding({ docsPlatform: 'cloudflare', diff --git a/static/app/gettingStartedDocs/node/cloudflare-workers/metrics.tsx b/static/app/gettingStartedDocs/node/cloudflare-workers/metrics.tsx index 1b1c02ac27411e..d7902e7ee03f31 100644 --- a/static/app/gettingStartedDocs/node/cloudflare-workers/metrics.tsx +++ b/static/app/gettingStartedDocs/node/cloudflare-workers/metrics.tsx @@ -1,4 +1,4 @@ -import {getNodeMetricsOnboarding} from 'sentry/gettingStartedDocs/node/node/utils'; +import {getNodeMetricsOnboarding} from 'sentry/gettingStartedDocs/node/node/metrics'; export const metrics = getNodeMetricsOnboarding({ docsPlatform: 'cloudflare', diff --git a/static/app/gettingStartedDocs/node/connect/metrics.tsx b/static/app/gettingStartedDocs/node/connect/metrics.tsx index 1d3f3df9d4ca14..84bd282891ea43 100644 --- a/static/app/gettingStartedDocs/node/connect/metrics.tsx +++ b/static/app/gettingStartedDocs/node/connect/metrics.tsx @@ -1,4 +1,4 @@ -import {getNodeMetricsOnboarding} from 'sentry/gettingStartedDocs/node/node/utils'; +import {getNodeMetricsOnboarding} from 'sentry/gettingStartedDocs/node/node/metrics'; export const metrics = getNodeMetricsOnboarding({ docsPlatform: 'connect', diff --git a/static/app/gettingStartedDocs/node/express/metrics.tsx b/static/app/gettingStartedDocs/node/express/metrics.tsx index 02e982a6174ac7..1126812e65aca5 100644 --- a/static/app/gettingStartedDocs/node/express/metrics.tsx +++ b/static/app/gettingStartedDocs/node/express/metrics.tsx @@ -1,4 +1,4 @@ -import {getNodeMetricsOnboarding} from 'sentry/gettingStartedDocs/node/node/utils'; +import {getNodeMetricsOnboarding} from 'sentry/gettingStartedDocs/node/node/metrics'; export const metrics = getNodeMetricsOnboarding({ docsPlatform: 'express', diff --git a/static/app/gettingStartedDocs/node/fastify/metrics.tsx b/static/app/gettingStartedDocs/node/fastify/metrics.tsx index f94f999be0192f..bda1d466bd2d02 100644 --- a/static/app/gettingStartedDocs/node/fastify/metrics.tsx +++ b/static/app/gettingStartedDocs/node/fastify/metrics.tsx @@ -1,4 +1,4 @@ -import {getNodeMetricsOnboarding} from 'sentry/gettingStartedDocs/node/node/utils'; +import {getNodeMetricsOnboarding} from 'sentry/gettingStartedDocs/node/node/metrics'; export const metrics = getNodeMetricsOnboarding({ docsPlatform: 'fastify', diff --git a/static/app/gettingStartedDocs/node/koa/metrics.tsx b/static/app/gettingStartedDocs/node/koa/metrics.tsx index fd892fa3322f6a..e6f55966758c27 100644 --- a/static/app/gettingStartedDocs/node/koa/metrics.tsx +++ b/static/app/gettingStartedDocs/node/koa/metrics.tsx @@ -1,4 +1,4 @@ -import {getNodeMetricsOnboarding} from 'sentry/gettingStartedDocs/node/node/utils'; +import {getNodeMetricsOnboarding} from 'sentry/gettingStartedDocs/node/node/metrics'; export const metrics = getNodeMetricsOnboarding({ docsPlatform: 'koa', diff --git a/static/app/gettingStartedDocs/node/nestjs/metrics.tsx b/static/app/gettingStartedDocs/node/nestjs/metrics.tsx index 8d65002ba9fa56..26e4db4a3ad486 100644 --- a/static/app/gettingStartedDocs/node/nestjs/metrics.tsx +++ b/static/app/gettingStartedDocs/node/nestjs/metrics.tsx @@ -1,4 +1,4 @@ -import {getNodeMetricsOnboarding} from 'sentry/gettingStartedDocs/node/node/utils'; +import {getNodeMetricsOnboarding} from 'sentry/gettingStartedDocs/node/node/metrics'; export const metrics = getNodeMetricsOnboarding({ docsPlatform: 'nestjs', diff --git a/static/app/gettingStartedDocs/node/node/metrics.tsx b/static/app/gettingStartedDocs/node/node/metrics.tsx index 7032f28f25ea9a..d493e87732c755 100644 --- a/static/app/gettingStartedDocs/node/node/metrics.tsx +++ b/static/app/gettingStartedDocs/node/node/metrics.tsx @@ -1,4 +1,106 @@ -import {getNodeMetricsOnboarding} from './utils'; +import {ExternalLink} from '@sentry/scraps/link'; + +import type { + BasePlatformOptions, + DocsParams, + OnboardingConfig, +} from 'sentry/components/onboarding/gettingStartedDoc/types'; +import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/types'; +import {getInstallCodeBlock} from 'sentry/gettingStartedDocs/node/node/utils'; +import {t, tct} from 'sentry/locale'; + +export const getNodeMetricsOnboarding = < + PlatformOptions extends BasePlatformOptions = BasePlatformOptions, +>({ + docsPlatform, + packageName, +}: { + docsPlatform: string; + packageName: `@sentry/${string}`; +}): OnboardingConfig => ({ + install: (params: DocsParams) => [ + { + type: StepType.INSTALL, + content: [ + { + type: 'text', + text: tct( + 'Add the Sentry SDK as a dependency. The minimum version of [packageName] that supports metrics is [code:10.24.0].', + { + code: , + packageName: {packageName}, + } + ), + }, + getInstallCodeBlock(params, {packageName}), + { + type: 'text', + text: tct( + 'If you are on an older version of the SDK, follow our [link:migration guide] to upgrade.', + { + link: ( + + ), + } + ), + }, + ], + }, + ], + configure: () => [ + { + type: StepType.CONFIGURE, + content: [ + { + type: 'text', + text: tct( + 'Metrics are automatically enabled after Sentry is initialized. You can emit metrics using the [code:Sentry.metrics] API.', + {code: } + ), + }, + { + type: 'text', + text: tct( + 'For more detailed information, see the [link:metrics documentation].', + { + link: ( + + ), + } + ), + }, + ], + }, + ], + verify: () => [ + { + type: StepType.VERIFY, + content: [ + { + type: 'text', + text: t( + 'Send a test metric from your app to verify metrics are arriving in Sentry.' + ), + }, + { + type: 'code', + language: 'javascript', + code: `const Sentry = require("${packageName}"); + +// Emit a test metric +Sentry.metrics.count('test_counter', 1); +Sentry.metrics.gauge('test_gauge', 100); +Sentry.metrics.distribution('test_distribution', 150); +`, + }, + ], + }, + ], +}); export const metrics = getNodeMetricsOnboarding({ docsPlatform: 'node', diff --git a/static/app/gettingStartedDocs/node/node/utils.tsx b/static/app/gettingStartedDocs/node/node/utils.tsx index cf105ecee0250a..aa4789c850efcf 100644 --- a/static/app/gettingStartedDocs/node/node/utils.tsx +++ b/static/app/gettingStartedDocs/node/node/utils.tsx @@ -852,99 +852,6 @@ Sentry.logger.info('User triggered test log', { action: 'test_log' })`, ], }); -export const getNodeMetricsOnboarding = < - PlatformOptions extends BasePlatformOptions = BasePlatformOptions, ->({ - docsPlatform, - packageName, -}: { - docsPlatform: string; - packageName: `@sentry/${string}`; -}): OnboardingConfig => ({ - install: (params: DocsParams) => [ - { - type: StepType.INSTALL, - content: [ - { - type: 'text', - text: tct( - 'Add the Sentry SDK as a dependency. The minimum version of [packageName] that supports metrics is [code:10.24.0].', - { - code: , - packageName: {packageName}, - } - ), - }, - getInstallCodeBlock(params, {packageName}), - { - type: 'text', - text: tct( - 'If you are on an older version of the SDK, follow our [link:migration guide] to upgrade.', - { - link: ( - - ), - } - ), - }, - ], - }, - ], - configure: () => [ - { - type: StepType.CONFIGURE, - content: [ - { - type: 'text', - text: tct( - 'Metrics are automatically enabled after Sentry is initialized. You can emit metrics using the [code:Sentry.metrics] API.', - {code: } - ), - }, - { - type: 'text', - text: tct( - 'For more detailed information, see the [link:metrics documentation].', - { - link: ( - - ), - } - ), - }, - ], - }, - ], - verify: () => [ - { - type: StepType.VERIFY, - content: [ - { - type: 'text', - text: t( - 'Send a test metric from your app to verify metrics are arriving in Sentry.' - ), - }, - { - type: 'code', - language: 'javascript', - code: `const Sentry = require("${packageName}"); - -// Emit a test metric -Sentry.metrics.count('test_counter', 1); -Sentry.metrics.gauge('test_gauge', 100); -Sentry.metrics.distribution('test_distribution', 150); -`, - }, - ], - }, - ], -}); - /** * Returns the init() with the necessary imports. It is possible to omit the imports. */ From f1971682759ff16f5de3a8ef231c58bcb5a21da2 Mon Sep 17 00:00:00 2001 From: Charly Gomez Date: Wed, 12 Nov 2025 13:22:23 +0100 Subject: [PATCH 3/3] fix snippet and bad merge --- .../node-cloudflare-pages/onboarding.tsx | 8 ++++---- .../node-cloudflare-workers/metrics.tsx | 2 +- static/app/gettingStartedDocs/node/metrics.tsx | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/static/app/gettingStartedDocs/node-cloudflare-pages/onboarding.tsx b/static/app/gettingStartedDocs/node-cloudflare-pages/onboarding.tsx index e137005daa6063..919250bd52f05a 100644 --- a/static/app/gettingStartedDocs/node-cloudflare-pages/onboarding.tsx +++ b/static/app/gettingStartedDocs/node-cloudflare-pages/onboarding.tsx @@ -59,10 +59,10 @@ export function onRequest(context) {${ // Send a log before throwing the error Sentry.logger.info('User triggered test error', { action: 'test_error_function', - });` + }); +` : '' -} -${ +}${ params.isMetricsSelected ? ` // Send a test metric before throwing the error @@ -72,7 +72,7 @@ Sentry.metrics.count('test_counter', 1); } setTimeout(() => { throw new Error(); -}`; +});}`; export const onboarding: OnboardingConfig = { introduction: () => diff --git a/static/app/gettingStartedDocs/node-cloudflare-workers/metrics.tsx b/static/app/gettingStartedDocs/node-cloudflare-workers/metrics.tsx index d7902e7ee03f31..84276655218806 100644 --- a/static/app/gettingStartedDocs/node-cloudflare-workers/metrics.tsx +++ b/static/app/gettingStartedDocs/node-cloudflare-workers/metrics.tsx @@ -1,4 +1,4 @@ -import {getNodeMetricsOnboarding} from 'sentry/gettingStartedDocs/node/node/metrics'; +import {getNodeMetricsOnboarding} from 'sentry/gettingStartedDocs/node/metrics'; export const metrics = getNodeMetricsOnboarding({ docsPlatform: 'cloudflare', diff --git a/static/app/gettingStartedDocs/node/metrics.tsx b/static/app/gettingStartedDocs/node/metrics.tsx index d493e87732c755..b2c892d3c2384c 100644 --- a/static/app/gettingStartedDocs/node/metrics.tsx +++ b/static/app/gettingStartedDocs/node/metrics.tsx @@ -6,7 +6,7 @@ import type { OnboardingConfig, } from 'sentry/components/onboarding/gettingStartedDoc/types'; import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/types'; -import {getInstallCodeBlock} from 'sentry/gettingStartedDocs/node/node/utils'; +import {getInstallCodeBlock} from 'sentry/gettingStartedDocs/node/utils'; import {t, tct} from 'sentry/locale'; export const getNodeMetricsOnboarding = <