Skip to content

Commit 5cd11c2

Browse files
authored
fix(sveltekit): Avoid creating the Sentry Vite plugin in dev mode (#8065)
Don't call the Vite plugin factory function in dev mode to keep the bundler plugin from leaking its telemetry tags to users' Sentry instance. We don't want to upload source maps in dev mode anyway.
1 parent 18bab90 commit 5cd11c2

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

packages/sveltekit/src/vite/sentryVitePlugins.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export async function sentrySvelteKit(options: SentrySvelteKitPluginOptions = {}
7878
);
7979
}
8080

81-
if (mergedOptions.autoUploadSourceMaps) {
81+
if (mergedOptions.autoUploadSourceMaps && process.env.NODE_ENV !== 'development') {
8282
const pluginOptions = {
8383
...mergedOptions.sourceMapsUploadOptions,
8484
debug: mergedOptions.debug, // override the plugin's debug flag with the one from the top-level options

packages/sveltekit/test/vite/sentrySvelteKitPlugins.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,19 @@ describe('sentryVite()', () => {
3838
expect(plugins).toHaveLength(1);
3939
});
4040

41+
it("doesn't return the custom sentry source maps plugin if `NODE_ENV` is development", async () => {
42+
const previousEnv = process.env.NODE_ENV;
43+
44+
process.env.NODE_ENV = 'development';
45+
const plugins = await sentrySvelteKit({ autoUploadSourceMaps: true, autoInstrument: true });
46+
const instrumentPlugin = plugins[0];
47+
48+
expect(plugins).toHaveLength(1);
49+
expect(instrumentPlugin.name).toEqual('sentry-auto-instrumentation');
50+
51+
process.env.NODE_ENV = previousEnv;
52+
});
53+
4154
it("doesn't return the auto instrument plugin if autoInstrument is `false`", async () => {
4255
const plugins = await sentrySvelteKit({ autoInstrument: false });
4356
expect(plugins).toHaveLength(1);

0 commit comments

Comments
 (0)