Skip to content

Commit

Permalink
fix(sveltekit): Avoid creating the Sentry Vite plugin in dev mode (#8065
Browse files Browse the repository at this point in the history
)

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.
  • Loading branch information
Lms24 authored May 8, 2023
1 parent 18bab90 commit 5cd11c2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/sveltekit/src/vite/sentryVitePlugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export async function sentrySvelteKit(options: SentrySvelteKitPluginOptions = {}
);
}

if (mergedOptions.autoUploadSourceMaps) {
if (mergedOptions.autoUploadSourceMaps && process.env.NODE_ENV !== 'development') {
const pluginOptions = {
...mergedOptions.sourceMapsUploadOptions,
debug: mergedOptions.debug, // override the plugin's debug flag with the one from the top-level options
Expand Down
13 changes: 13 additions & 0 deletions packages/sveltekit/test/vite/sentrySvelteKitPlugins.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,19 @@ describe('sentryVite()', () => {
expect(plugins).toHaveLength(1);
});

it("doesn't return the custom sentry source maps plugin if `NODE_ENV` is development", async () => {
const previousEnv = process.env.NODE_ENV;

process.env.NODE_ENV = 'development';
const plugins = await sentrySvelteKit({ autoUploadSourceMaps: true, autoInstrument: true });
const instrumentPlugin = plugins[0];

expect(plugins).toHaveLength(1);
expect(instrumentPlugin.name).toEqual('sentry-auto-instrumentation');

process.env.NODE_ENV = previousEnv;
});

it("doesn't return the auto instrument plugin if autoInstrument is `false`", async () => {
const plugins = await sentrySvelteKit({ autoInstrument: false });
expect(plugins).toHaveLength(1);
Expand Down

0 comments on commit 5cd11c2

Please sign in to comment.