Skip to content

Commit 47e7385

Browse files
committed
extract common init options snippet builder
1 parent 65c934b commit 47e7385

File tree

2 files changed

+14
-16
lines changed

2 files changed

+14
-16
lines changed

packages/astro/src/integration/snippets.ts

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,10 @@ export function buildClientSnippet(options: SentryOptions): string {
1515
return `import * as Sentry from "@sentry/astro";
1616
1717
Sentry.init({
18-
dsn: ${options.dsn ? JSON.stringify(options.dsn) : 'import.meta.env.PUBLIC_SENTRY_DSN'},
19-
debug: ${options.debug ? true : false},
20-
environment: ${options.environment ? JSON.stringify(options.environment) : 'import.meta.env.PUBLIC_VERCEL_ENV'},
21-
release: ${options.release ? JSON.stringify(options.release) : 'import.meta.env.PUBLIC_VERCEL_GIT_COMMIT_SHA'},
18+
${buildCommonInitOptions(options)}
2219
integrations: [new Sentry.BrowserTracing(), new Sentry.Replay()],
23-
tracesSampleRate: ${options.tracesSampleRate ?? 1.0},
2420
replaysSessionSampleRate: ${options.replaysSessionSampleRate ?? 0.1},
25-
replaysOnErrorSampleRate: ${options.replaysOnErrorSampleRate ?? 1.0},${
26-
options.sampleRate ? `\n sampleRate: ${options.sampleRate},` : ''
27-
}
21+
replaysOnErrorSampleRate: ${options.replaysOnErrorSampleRate ?? 1.0},
2822
});`;
2923
}
3024

@@ -36,12 +30,16 @@ export function buildServerSnippet(options: SentryOptions): string {
3630
return `import * as Sentry from "@sentry/astro";
3731
3832
Sentry.init({
39-
dsn: ${options.dsn ? JSON.stringify(options.dsn) : 'import.meta.env.PUBLIC_SENTRY_DSN'},
33+
${buildCommonInitOptions(options)}
34+
});`;
35+
}
36+
37+
const buildCommonInitOptions = (options: SentryOptions): string => `dsn: ${
38+
options.dsn ? JSON.stringify(options.dsn) : 'import.meta.env.PUBLIC_SENTRY_DSN'
39+
},
4040
debug: ${options.debug ? true : false},
4141
environment: ${options.environment ? JSON.stringify(options.environment) : 'import.meta.env.PUBLIC_VERCEL_ENV'},
4242
release: ${options.release ? JSON.stringify(options.release) : 'import.meta.env.PUBLIC_VERCEL_GIT_COMMIT_SHA'},
4343
tracesSampleRate: ${options.tracesSampleRate ?? 1.0},${
44-
options.sampleRate ? `\n sampleRate: ${options.sampleRate},` : ''
45-
}
46-
});`;
47-
}
44+
options.sampleRate ? `\n sampleRate: ${options.sampleRate},` : ''
45+
}`;

packages/astro/test/integration/snippets.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ describe('buildClientSnippet', () => {
2222
debug: false,
2323
environment: import.meta.env.PUBLIC_VERCEL_ENV,
2424
release: import.meta.env.PUBLIC_VERCEL_GIT_COMMIT_SHA,
25-
integrations: [new Sentry.BrowserTracing(), new Sentry.Replay()],
2625
tracesSampleRate: 1,
26+
integrations: [new Sentry.BrowserTracing(), new Sentry.Replay()],
2727
replaysSessionSampleRate: 0.1,
2828
replaysOnErrorSampleRate: 1,
2929
});"
@@ -41,11 +41,11 @@ describe('buildClientSnippet', () => {
4141
debug: true,
4242
environment: \\"staging\\",
4343
release: \\"1.0.0\\",
44-
integrations: [new Sentry.BrowserTracing(), new Sentry.Replay()],
4544
tracesSampleRate: 0.3,
45+
sampleRate: 0.2,
46+
integrations: [new Sentry.BrowserTracing(), new Sentry.Replay()],
4647
replaysSessionSampleRate: 0.5,
4748
replaysOnErrorSampleRate: 0.4,
48-
sampleRate: 0.2,
4949
});"
5050
`);
5151
});

0 commit comments

Comments
 (0)