Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -12,6 +13,7 @@ const docs: Docs = {
logsOnboarding: logs,
agentMonitoringOnboarding: agentMonitoring,
mcpOnboarding: mcp,
metricsOnboarding: metrics,
};

export default docs;
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import {getNodeMetricsOnboarding} from 'sentry/gettingStartedDocs/node/metrics';

export const metrics = getNodeMetricsOnboarding({
docsPlatform: 'cloudflare',
packageName: '@sentry/cloudflare',
});
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,20 @@ 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
Sentry.metrics.count('test_counter', 1);
`
: ''
}
setTimeout(() => {
throw new Error();
}`;
});}`;

export const onboarding: OnboardingConfig = {
introduction: () =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -12,6 +13,7 @@ const docs: Docs = {
logsOnboarding: logs,
agentMonitoringOnboarding: agentMonitoring,
mcpOnboarding: mcp,
metricsOnboarding: metrics,
};

export default docs;
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import {getNodeMetricsOnboarding} from 'sentry/gettingStartedDocs/node/metrics';

export const metrics = getNodeMetricsOnboarding({
docsPlatform: 'cloudflare',
packageName: '@sentry/cloudflare',
});
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ Sentry.logger.info('User triggered test error', {
action: 'test_error_worker',
});`
: ''
}${
params.isMetricsSelected
? `
// Send a test metric before throwing the error
Sentry.metrics.count('test_counter', 1);
`
: ''
}
setTimeout(() => {
throw new Error();
Expand Down
2 changes: 1 addition & 1 deletion static/app/gettingStartedDocs/node-connect/metrics.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {getNodeMetricsOnboarding} from 'sentry/gettingStartedDocs/node/utils';
import {getNodeMetricsOnboarding} from 'sentry/gettingStartedDocs/node/metrics';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no tests for metrics?


export const metrics = getNodeMetricsOnboarding({
docsPlatform: 'connect',
Expand Down
2 changes: 1 addition & 1 deletion static/app/gettingStartedDocs/node-express/metrics.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {getNodeMetricsOnboarding} from 'sentry/gettingStartedDocs/node/utils';
import {getNodeMetricsOnboarding} from 'sentry/gettingStartedDocs/node/metrics';

export const metrics = getNodeMetricsOnboarding({
docsPlatform: 'express',
Expand Down
2 changes: 1 addition & 1 deletion static/app/gettingStartedDocs/node-fastify/metrics.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {getNodeMetricsOnboarding} from 'sentry/gettingStartedDocs/node/utils';
import {getNodeMetricsOnboarding} from 'sentry/gettingStartedDocs/node/metrics';

export const metrics = getNodeMetricsOnboarding({
docsPlatform: 'fastify',
Expand Down
2 changes: 1 addition & 1 deletion static/app/gettingStartedDocs/node-koa/metrics.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {getNodeMetricsOnboarding} from 'sentry/gettingStartedDocs/node/utils';
import {getNodeMetricsOnboarding} from 'sentry/gettingStartedDocs/node/metrics';

export const metrics = getNodeMetricsOnboarding({
docsPlatform: 'koa',
Expand Down
2 changes: 1 addition & 1 deletion static/app/gettingStartedDocs/node-nestjs/metrics.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {getNodeMetricsOnboarding} from 'sentry/gettingStartedDocs/node/utils';
import {getNodeMetricsOnboarding} from 'sentry/gettingStartedDocs/node/metrics';

export const metrics = getNodeMetricsOnboarding({
docsPlatform: 'nestjs',
Expand Down
104 changes: 103 additions & 1 deletion static/app/gettingStartedDocs/node/metrics.tsx
Original file line number Diff line number Diff line change
@@ -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/utils';
import {t, tct} from 'sentry/locale';

export const getNodeMetricsOnboarding = <
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for creating this file and for moving the function out of utils <3

I would just name this metrics and inline this part export const metrics = getNodeMetricsOnboarding({ in the index file.

PlatformOptions extends BasePlatformOptions = BasePlatformOptions,
>({
docsPlatform,
packageName,
}: {
docsPlatform: string;
packageName: `@sentry/${string}`;
}): OnboardingConfig<PlatformOptions> => ({
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: <code />,
packageName: <code>{packageName}</code>,
}
),
},
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: (
<ExternalLink
href={`https://docs.sentry.io/platforms/javascript/guides/${docsPlatform}/migration/`}
/>
),
}
),
},
],
},
],
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: <code />}
),
},
{
type: 'text',
text: tct(
'For more detailed information, see the [link:metrics documentation].',
{
link: (
<ExternalLink
href={`https://docs.sentry.io/platforms/javascript/guides/${docsPlatform}/metrics/`}
/>
),
}
),
},
],
},
],
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',
Expand Down
109 changes: 0 additions & 109 deletions static/app/gettingStartedDocs/node/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -852,115 +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<PlatformOptions> => ({
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: <code />,
packageName: <code>{packageName}</code>,
}
),
},
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: (
<ExternalLink
href={`https://docs.sentry.io/platforms/javascript/guides/${docsPlatform}/migration/`}
/>
),
}
),
},
],
},
],
configure: (params: DocsParams) => [
{
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.',
{code: <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(
'For more detailed information, see the [link:metrics documentation].',
{
link: (
<ExternalLink
href={`https://docs.sentry.io/platforms/javascript/guides/${docsPlatform}/metrics/`}
/>
),
}
),
},
],
},
],
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.
*/
Expand Down
Loading