Skip to content

Commit 8d95c21

Browse files
committed
add node snippet
1 parent 44ea2b2 commit 8d95c21

File tree

5 files changed

+181
-1
lines changed

5 files changed

+181
-1
lines changed

static/app/gettingStartedDocs/node/node/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {agentMonitoring} from './agentMonitoring';
88
import {crashReport} from './crashReport';
99
import {logs} from './logs';
1010
import {mcp} from './mcp';
11+
import {metrics} from './metrics';
1112
import {onboarding} from './onboarding';
1213
import {performance} from './performance';
1314
import {profiling} from './profiling';
@@ -20,6 +21,7 @@ const docs: Docs = {
2021
feedbackOnboardingJsLoader,
2122
profilingOnboarding: profiling,
2223
logsOnboarding: logs,
24+
metricsOnboarding: metrics,
2325
agentMonitoringOnboarding: agentMonitoring,
2426
mcpOnboarding: mcp,
2527
};
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import {getNodeMetricsOnboarding} from './utils';
2+
3+
export const metrics = getNodeMetricsOnboarding({
4+
docsPlatform: 'node',
5+
packageName: '@sentry/node',
6+
});

static/app/gettingStartedDocs/node/node/onboarding.spec.tsx

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,4 +170,44 @@ describe('node onboarding docs', () => {
170170
)
171171
).not.toBeInTheDocument();
172172
});
173+
174+
it('displays metrics code in verify section when metrics are selected', () => {
175+
renderWithOnboardingLayout(docs, {
176+
selectedProducts: [ProductSolution.ERROR_MONITORING, ProductSolution.METRICS],
177+
});
178+
179+
expect(
180+
screen.getByText(
181+
textWithMarkupMatcher(/Sentry\.metrics\.count\('test_counter', 1\)/)
182+
)
183+
).toBeInTheDocument();
184+
});
185+
186+
it('does not display metrics code in verify section when metrics are not selected', () => {
187+
renderWithOnboardingLayout(docs, {
188+
selectedProducts: [ProductSolution.ERROR_MONITORING],
189+
});
190+
191+
expect(
192+
screen.queryByText(
193+
textWithMarkupMatcher(/Sentry\.metrics\.count\('test_counter', 1\)/)
194+
)
195+
).not.toBeInTheDocument();
196+
});
197+
198+
it('displays Metrics in next steps when metrics are selected', () => {
199+
renderWithOnboardingLayout(docs, {
200+
selectedProducts: [ProductSolution.ERROR_MONITORING, ProductSolution.METRICS],
201+
});
202+
203+
expect(screen.getByText('Metrics')).toBeInTheDocument();
204+
});
205+
206+
it('does not display Metrics in next steps when metrics are not selected', () => {
207+
renderWithOnboardingLayout(docs, {
208+
selectedProducts: [ProductSolution.ERROR_MONITORING],
209+
});
210+
211+
expect(screen.queryByText('Metrics')).not.toBeInTheDocument();
212+
});
173213
});

static/app/gettingStartedDocs/node/node/onboarding.tsx

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,12 @@ Sentry.startSpan({
260260
action: 'test_error_span',
261261
});`
262262
: ''
263+
}${
264+
params.isMetricsSelected
265+
? `
266+
// Send a test metric before throwing the error
267+
Sentry.metrics.count('test_counter', 1);`
268+
: ''
263269
}
264270
foo();
265271
} catch (e) {
@@ -276,7 +282,13 @@ Sentry.logger.info('User triggered test error', {
276282
action: 'test_error_basic',
277283
});`
278284
: ''
279-
}
285+
}${
286+
params.isMetricsSelected
287+
? `
288+
// Send a test metric before throwing the error
289+
Sentry.metrics.count('test_counter', 1);`
290+
: ''
291+
}
280292
try {
281293
foo();
282294
} catch (e) {
@@ -300,6 +312,17 @@ try {
300312
});
301313
}
302314

315+
if (params.isMetricsSelected) {
316+
steps.push({
317+
id: 'metrics',
318+
name: t('Metrics'),
319+
description: t(
320+
'Learn how to track custom metrics to monitor your application performance and business KPIs.'
321+
),
322+
link: 'https://docs.sentry.io/platforms/javascript/guides/node/metrics/',
323+
});
324+
}
325+
303326
return steps;
304327
},
305328
};

static/app/gettingStartedDocs/node/node/utils.tsx

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -852,6 +852,115 @@ Sentry.logger.info('User triggered test log', { action: 'test_log' })`,
852852
],
853853
});
854854

855+
export const getNodeMetricsOnboarding = <
856+
PlatformOptions extends BasePlatformOptions = BasePlatformOptions,
857+
>({
858+
docsPlatform,
859+
packageName,
860+
}: {
861+
docsPlatform: string;
862+
packageName: `@sentry/${string}`;
863+
}): OnboardingConfig<PlatformOptions> => ({
864+
install: (params: DocsParams) => [
865+
{
866+
type: StepType.INSTALL,
867+
content: [
868+
{
869+
type: 'text',
870+
text: tct(
871+
'Add the Sentry SDK as a dependency. The minimum version of [packageName] that supports metrics is [code:10.24.0].',
872+
{
873+
code: <code />,
874+
packageName: <code>{packageName}</code>,
875+
}
876+
),
877+
},
878+
getInstallCodeBlock(params, {packageName}),
879+
{
880+
type: 'text',
881+
text: tct(
882+
'If you are on an older version of the SDK, follow our [link:migration guide] to upgrade.',
883+
{
884+
link: (
885+
<ExternalLink
886+
href={`https://docs.sentry.io/platforms/javascript/guides/${docsPlatform}/migration/`}
887+
/>
888+
),
889+
}
890+
),
891+
},
892+
],
893+
},
894+
],
895+
configure: (params: DocsParams) => [
896+
{
897+
type: StepType.CONFIGURE,
898+
content: [
899+
{
900+
type: 'text',
901+
text: tct(
902+
'Metrics are automatically enabled in your [code:Sentry.init()] configuration. You can emit metrics using the [code:Sentry.metrics] API.',
903+
{code: <code />}
904+
),
905+
},
906+
{
907+
type: 'code',
908+
language: 'javascript',
909+
code: `
910+
const Sentry = require("${packageName}");
911+
912+
Sentry.init({
913+
dsn: "${params.dsn.public}",
914+
});
915+
916+
// Emit custom metrics
917+
Sentry.metrics.count('button_click', 1);
918+
Sentry.metrics.gauge('page_load_time', 150);
919+
Sentry.metrics.distribution('response_time', 200);
920+
`,
921+
},
922+
{
923+
type: 'text',
924+
text: tct(
925+
'For more detailed information, see the [link:metrics documentation].',
926+
{
927+
link: (
928+
<ExternalLink
929+
href={`https://docs.sentry.io/platforms/javascript/guides/${docsPlatform}/metrics/`}
930+
/>
931+
),
932+
}
933+
),
934+
},
935+
],
936+
},
937+
],
938+
verify: () => [
939+
{
940+
type: StepType.VERIFY,
941+
content: [
942+
{
943+
type: 'text',
944+
text: t(
945+
'Send a test metric from your app to verify metrics are arriving in Sentry.'
946+
),
947+
},
948+
{
949+
type: 'code',
950+
language: 'javascript',
951+
code: `const Sentry = require("${packageName}");
952+
953+
// Emit a test metric
954+
Sentry.metrics.count('test_counter', 1);
955+
Sentry.metrics.gauge('test_gauge', 100);
956+
Sentry.metrics.distribution('test_distribution', 150);
957+
`,
958+
},
959+
],
960+
},
961+
],
962+
});
963+
855964
/**
856965
* Returns the init() with the necessary imports. It is possible to omit the imports.
857966
*/

0 commit comments

Comments
 (0)