Skip to content

Commit f907537

Browse files
committed
add metrics code snippets
1 parent 7cd66b4 commit f907537

File tree

15 files changed

+394
-71
lines changed

15 files changed

+394
-71
lines changed

static/app/gettingStartedDocs/javascript/angular/onboarding.tsx

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ const getVerifySnippetTemplate = () => `
7070
`;
7171

7272
const getVerifySnippetComponent = (params: Params) => `${
73-
params.isLogsSelected ? 'import * as Sentry from "@sentry/angular";\n\n' : ''
73+
params.isLogsSelected || params.isMetricsSelected
74+
? 'import * as Sentry from "@sentry/angular";\n\n'
75+
: ''
7476
}export class AppComponent {
7577
public throwTestError(): void {${
7678
params.isLogsSelected
@@ -80,6 +82,12 @@ const getVerifySnippetComponent = (params: Params) => `${
8082
action: "test_error_button_click",
8183
});`
8284
: ''
85+
}${
86+
params.isMetricsSelected
87+
? `
88+
// Send a test metric before throwing the error
89+
Sentry.metrics.count('test_counter', 1);`
90+
: ''
8391
}
8492
throw new Error("Sentry Test Error");
8593
}
@@ -242,6 +250,17 @@ export const onboarding: OnboardingConfig<PlatformOptions> = {
242250
});
243251
}
244252

253+
if (params.isMetricsSelected) {
254+
steps.push({
255+
id: 'metrics',
256+
name: t('Metrics'),
257+
description: t(
258+
'Learn how to track custom metrics to monitor your application performance and business KPIs.'
259+
),
260+
link: 'https://docs.sentry.io/platforms/javascript/guides/angular/metrics/',
261+
});
262+
}
263+
245264
return steps;
246265
},
247266
};

static/app/gettingStartedDocs/javascript/astro/onboarding.tsx

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,18 +96,24 @@ const getVerifySnippet = (params: DocsParams) => {
9696
});`
9797
: '';
9898

99+
const metricsCode = params.isMetricsSelected
100+
? `
101+
// Send a test metric before throwing the error
102+
Sentry.metrics.count('test_counter', 1);`
103+
: '';
104+
99105
return `
100106
<!-- your-page.astro -->
101107
---
102108
---
103109
<button id="error-button">Throw test error</button>
104110
<script>${
105-
params.isLogsSelected
111+
params.isLogsSelected || params.isMetricsSelected
106112
? `
107113
import * as Sentry from "@sentry/astro";`
108114
: ''
109115
}
110-
function handleClick () {${logsCode}
116+
function handleClick () {${logsCode}${metricsCode}
111117
throw new Error('This is a test error');
112118
}
113119
document.querySelector("#error-button").addEventListener("click", handleClick);
@@ -311,6 +317,17 @@ export const onboarding: OnboardingConfig = {
311317
});
312318
}
313319

320+
if (params.isMetricsSelected) {
321+
steps.push({
322+
id: 'metrics',
323+
name: t('Metrics'),
324+
description: t(
325+
'Learn how to track custom metrics to monitor your application performance and business KPIs.'
326+
),
327+
link: 'https://docs.sentry.io/platforms/javascript/guides/astro/metrics/',
328+
});
329+
}
330+
314331
return steps;
315332
},
316333
};

static/app/gettingStartedDocs/javascript/ember/onboarding.tsx

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,17 @@ const getVerifyEmberSnippet = (params: DocsParams) => {
1717
`
1818
: '';
1919

20+
const metricsCode = params.isMetricsSelected
21+
? `// Send a test metric before throwing the error
22+
Sentry.metrics.count('test_counter', 1);
23+
`
24+
: '';
25+
2026
return `
2127
import * as Sentry from "@sentry/ember";
2228
2329
setTimeout(() => {
24-
${logsCode}throw new Error("Sentry Test Error");
30+
${logsCode}${metricsCode}throw new Error("Sentry Test Error");
2531
});`;
2632
};
2733

@@ -120,6 +126,17 @@ export const onboarding: OnboardingConfig = {
120126
});
121127
}
122128

129+
if (params.isMetricsSelected) {
130+
steps.push({
131+
id: 'metrics',
132+
name: t('Metrics'),
133+
description: t(
134+
'Learn how to track custom metrics to monitor your application performance and business KPIs.'
135+
),
136+
link: 'https://docs.sentry.io/platforms/javascript/guides/ember/metrics/',
137+
});
138+
}
139+
123140
return steps;
124141
},
125142
};

static/app/gettingStartedDocs/javascript/gatsby/onboarding.tsx

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,17 @@ const getVerifySnippet = (params: DocsParams) => {
1717
`
1818
: '';
1919

20+
const metricsCode = params.isMetricsSelected
21+
? `// Send a test metric before throwing the error
22+
Sentry.metrics.count('test_counter', 1);
23+
`
24+
: '';
25+
2026
return `
2127
import * as Sentry from "@sentry/gatsby";
2228
2329
setTimeout(() => {
24-
${logsCode}throw new Error("Sentry Test Error");
30+
${logsCode}${metricsCode}throw new Error("Sentry Test Error");
2531
});`;
2632
};
2733

@@ -92,6 +98,17 @@ export const onboarding: OnboardingConfig = {
9298
});
9399
}
94100

101+
if (params.isMetricsSelected) {
102+
steps.push({
103+
id: 'metrics',
104+
name: t('Metrics'),
105+
description: t(
106+
'Learn how to track custom metrics to monitor your application performance and business KPIs.'
107+
),
108+
link: 'https://docs.sentry.io/platforms/javascript/guides/gatsby/metrics/',
109+
});
110+
}
111+
95112
return steps;
96113
},
97114
};

static/app/gettingStartedDocs/javascript/javascript/utils.tsx

Lines changed: 56 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,17 @@ export const installSnippetBlock: ContentBlock = {
148148
],
149149
};
150150

151-
const getVerifyJSSnippet = () => `
152-
myUndefinedFunction();`;
151+
const getVerifyJSSnippet = (params: Params) => {
152+
const metricsCode = params.isMetricsSelected
153+
? ` // Send a test metric before calling undefined function
154+
Sentry.metrics.count('test_counter', 1);
155+
`
156+
: '';
157+
158+
return `${metricsCode}myUndefinedFunction();`;
159+
};
153160

154-
export const verifySnippetBlock: ContentBlock[] = [
161+
const getVerifySnippetBlock = (params: Params): ContentBlock[] => [
155162
{
156163
type: 'text',
157164
text: t(
@@ -164,7 +171,7 @@ export const verifySnippetBlock: ContentBlock[] = [
164171
{
165172
label: 'Javascript',
166173
language: 'javascript',
167-
code: getVerifyJSSnippet(),
174+
code: getVerifyJSSnippet(params),
168175
},
169176
],
170177
},
@@ -305,10 +312,10 @@ logger.fatal("Database connection pool exhausted", {
305312
`,
306313
});
307314

308-
const getVerifyConfig = () => [
315+
const getVerifyConfig = (params: Params) => [
309316
{
310317
type: StepType.VERIFY,
311-
content: verifySnippetBlock,
318+
content: getVerifySnippetBlock(params),
312319
},
313320
];
314321

@@ -440,15 +447,32 @@ export const loaderScriptOnboarding: OnboardingConfig<PlatformOptions> = {
440447
},
441448
getAiRulesConfig(params),
442449
],
443-
verify: getVerifyConfig,
444-
nextSteps: () => [
445-
{
446-
id: 'source-maps',
447-
name: t('Source Maps'),
448-
description: t('Learn how to enable readable stack traces in your Sentry errors.'),
449-
link: 'https://docs.sentry.io/platforms/javascript/sourcemaps/',
450-
},
451-
],
450+
verify: (params: Params) => getVerifyConfig(params),
451+
nextSteps: (params: Params) => {
452+
const steps = [
453+
{
454+
id: 'source-maps',
455+
name: t('Source Maps'),
456+
description: t(
457+
'Learn how to enable readable stack traces in your Sentry errors.'
458+
),
459+
link: 'https://docs.sentry.io/platforms/javascript/sourcemaps/',
460+
},
461+
];
462+
463+
if (params.isMetricsSelected) {
464+
steps.push({
465+
id: 'metrics',
466+
name: t('Metrics'),
467+
description: t(
468+
'Learn how to track custom metrics to monitor your application performance and business KPIs.'
469+
),
470+
link: 'https://docs.sentry.io/platforms/javascript/guides/javascript/metrics/',
471+
});
472+
}
473+
474+
return steps;
475+
},
452476
onPageLoad: params => {
453477
return () => {
454478
trackAnalytics('onboarding.setup_loader_docs_rendered', {
@@ -542,8 +566,23 @@ export const packageManagerOnboarding: OnboardingConfig<PlatformOptions> = {
542566
}),
543567
getAiRulesConfig(params),
544568
],
545-
verify: getVerifyConfig,
546-
nextSteps: () => [],
569+
verify: (params: Params) => getVerifyConfig(params),
570+
nextSteps: (params: Params) => {
571+
const steps = [];
572+
573+
if (params.isMetricsSelected) {
574+
steps.push({
575+
id: 'metrics',
576+
name: t('Metrics'),
577+
description: t(
578+
'Learn how to track custom metrics to monitor your application performance and business KPIs.'
579+
),
580+
link: 'https://docs.sentry.io/platforms/javascript/guides/javascript/metrics/',
581+
});
582+
}
583+
584+
return steps;
585+
},
547586
onPageLoad: params => {
548587
return () => {
549588
trackAnalytics('onboarding.js_loader_npm_docs_shown', {

static/app/gettingStartedDocs/javascript/nextjs/onboarding.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@ import {t, tct} from 'sentry/locale';
1010

1111
import {getInstallSnippet} from './utils';
1212

13+
const getVerifySnippet = (params: DocsParams) => {
14+
const metricsCode = params.isMetricsSelected
15+
? ` // Send a test metric before calling undefined function
16+
Sentry.metrics.count('test_counter', 1);
17+
`
18+
: '';
19+
20+
return `${metricsCode}myUndefinedFunction();`;
21+
};
22+
1323
export const onboarding: OnboardingConfig = {
1424
install: (params: DocsParams) => [
1525
{
@@ -189,7 +199,7 @@ logger.fatal("Database connection pool exhausted", {
189199
`,
190200
}),
191201
],
192-
verify: () => [
202+
verify: (params: DocsParams) => [
193203
{
194204
type: StepType.VERIFY,
195205
content: [
@@ -214,7 +224,7 @@ logger.fatal("Database connection pool exhausted", {
214224
{
215225
label: 'JavaScript',
216226
language: 'javascript',
217-
code: `myUndefinedFunction();`,
227+
code: getVerifySnippet(params),
218228
},
219229
],
220230
},

static/app/gettingStartedDocs/javascript/nuxt/onboarding.tsx

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,28 @@ import {t, tct, tctCode} from 'sentry/locale';
99

1010
import {getInstallContent} from './utils';
1111

12-
const getVerifyNuxtSnippet = () => `
13-
<script setup>
14-
const triggerError = () => {
12+
const getVerifyNuxtSnippet = (params: DocsParams) => {
13+
const metricsCode = params.isMetricsSelected
14+
? `
15+
// Send a test metric before throwing the error
16+
Sentry.metrics.count('test_counter', 1);`
17+
: '';
18+
19+
const importSentry = params.isMetricsSelected
20+
? `\nimport * as Sentry from "@sentry/nuxt";\n`
21+
: '';
22+
23+
return `
24+
<script setup>${importSentry}
25+
const triggerError = () => {${metricsCode}
1526
throw new Error("Nuxt Button Error");
1627
};
1728
</script>
1829
1930
<template>
2031
<button id="errorBtn" @click="triggerError">Trigger Error</button>
2132
</template>`;
33+
};
2234

2335
export const onboarding: OnboardingConfig = {
2436
install: (params: DocsParams) => [
@@ -50,7 +62,7 @@ export const onboarding: OnboardingConfig = {
5062
],
5163
},
5264
],
53-
verify: () => [
65+
verify: (params: DocsParams) => [
5466
{
5567
type: StepType.VERIFY,
5668
content: [
@@ -70,7 +82,7 @@ export const onboarding: OnboardingConfig = {
7082
{
7183
label: 'Vue',
7284
language: 'html',
73-
code: getVerifyNuxtSnippet(),
85+
code: getVerifyNuxtSnippet(params),
7486
},
7587
],
7688
},
@@ -83,12 +95,29 @@ export const onboarding: OnboardingConfig = {
8395
],
8496
},
8597
],
86-
nextSteps: () => [
87-
{
88-
id: 'nuxt-features',
89-
name: t('Nuxt Features'),
90-
description: t('Learn about our first class integration with the Nuxt framework.'),
91-
link: 'https://docs.sentry.io/platforms/javascript/guides/nuxt/features/',
92-
},
93-
],
98+
nextSteps: (params: DocsParams) => {
99+
const steps = [
100+
{
101+
id: 'nuxt-features',
102+
name: t('Nuxt Features'),
103+
description: t(
104+
'Learn about our first class integration with the Nuxt framework.'
105+
),
106+
link: 'https://docs.sentry.io/platforms/javascript/guides/nuxt/features/',
107+
},
108+
];
109+
110+
if (params.isMetricsSelected) {
111+
steps.push({
112+
id: 'metrics',
113+
name: t('Metrics'),
114+
description: t(
115+
'Learn how to track custom metrics to monitor your application performance and business KPIs.'
116+
),
117+
link: 'https://docs.sentry.io/platforms/javascript/guides/nuxt/metrics/',
118+
});
119+
}
120+
121+
return steps;
122+
},
94123
};

0 commit comments

Comments
 (0)