From 4dbd7fa25c798de4f61544aa2b3fd59e1fd5a986 Mon Sep 17 00:00:00 2001 From: Charly Gomez Date: Tue, 28 Jul 2026 16:58:40 +0200 Subject: [PATCH 1/3] e2e --- .../sveltekit-2-orchestrion/package.json | 1 - .../sveltekit-2-orchestrion/vite.config.ts | 9 +++------ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/dev-packages/e2e-tests/test-applications/sveltekit-2-orchestrion/package.json b/dev-packages/e2e-tests/test-applications/sveltekit-2-orchestrion/package.json index 59069913902e..b88f3a62ccc1 100644 --- a/dev-packages/e2e-tests/test-applications/sveltekit-2-orchestrion/package.json +++ b/dev-packages/e2e-tests/test-applications/sveltekit-2-orchestrion/package.json @@ -18,7 +18,6 @@ }, "//": "Need to use ioredis 5.10.1 because that's the last version before they support tracing channels", "dependencies": { - "@sentry/server-utils": "file:../../packed/sentry-server-utils-packed.tgz", "@sentry/sveltekit": "file:../../packed/sentry-sveltekit-packed.tgz", "ioredis": "5.10.1", "mysql": "^2.18.1" diff --git a/dev-packages/e2e-tests/test-applications/sveltekit-2-orchestrion/vite.config.ts b/dev-packages/e2e-tests/test-applications/sveltekit-2-orchestrion/vite.config.ts index 9a08b8d48133..d902d792b3ae 100644 --- a/dev-packages/e2e-tests/test-applications/sveltekit-2-orchestrion/vite.config.ts +++ b/dev-packages/e2e-tests/test-applications/sveltekit-2-orchestrion/vite.config.ts @@ -1,19 +1,16 @@ import { sentrySvelteKit } from '@sentry/sveltekit'; -import { sentryOrchestrionPlugin } from '@sentry/server-utils/orchestrion/vite'; import { sveltekit } from '@sveltejs/kit/vite'; import { defineConfig } from 'vite'; export default defineConfig({ plugins: [ + // `sentrySvelteKit()` wires up the orchestrion code transform automatically, so + // instrumented DB drivers (mysql, ioredis) get `diagnostics_channel` publishers + // injected into the SSR bundle with no manual plugin needed. sentrySvelteKit({ autoUploadSourceMaps: false, }), - // Runs the orchestrion code transform on the SvelteKit SSR bundle so - // instrumented DB drivers (mysql, ioredis) get `diagnostics_channel` - // publishers injected at build time. - sentryOrchestrionPlugin(), - sveltekit(), ], }); From 4e1f326c96c752ca200054b5c07c4323d50a38d7 Mon Sep 17 00:00:00 2001 From: Charly Gomez Date: Tue, 28 Jul 2026 16:58:44 +0200 Subject: [PATCH 2/3] add dep --- packages/sveltekit/package.json | 1 + .../sveltekit/src/vite/sentryVitePlugins.ts | 8 ++++ .../test/vite/sentrySvelteKitPlugins.test.ts | 46 ++++++++++++++++--- 3 files changed, 49 insertions(+), 6 deletions(-) diff --git a/packages/sveltekit/package.json b/packages/sveltekit/package.json index a5ead3979092..81d742edfcd9 100644 --- a/packages/sveltekit/package.json +++ b/packages/sveltekit/package.json @@ -60,6 +60,7 @@ "@sentry/core": "10.67.0", "@sentry/conventions": "^0.16.0", "@sentry/node": "10.67.0", + "@sentry/server-utils": "10.67.0", "@sentry/svelte": "10.67.0", "@sentry/bundler-plugins": "10.67.0", "@sveltejs/acorn-typescript": "^1.0.9", diff --git a/packages/sveltekit/src/vite/sentryVitePlugins.ts b/packages/sveltekit/src/vite/sentryVitePlugins.ts index 2377c1e7f65c..df18ecb53283 100644 --- a/packages/sveltekit/src/vite/sentryVitePlugins.ts +++ b/packages/sveltekit/src/vite/sentryVitePlugins.ts @@ -1,4 +1,5 @@ import { consoleSandbox } from '@sentry/core'; +import { sentryOrchestrionPlugin } from '@sentry/server-utils/orchestrion/vite'; import * as fs from 'fs'; import * as path from 'path'; import type { Plugin } from 'vite'; @@ -54,6 +55,13 @@ export async function sentrySvelteKit(options: SentrySvelteKitPluginOptions = {} ); } + // Auto-instrument server-side dependencies at build time (mysql, ioredis, …) by injecting + // `diagnostics_channel` publishers. The plugin self-scopes to the SSR build and honors + // `buildTimeInstrumentation: false` itself. Cloudflare/workerd is not supported yet. + if (mergedOptions.adapter !== 'cloudflare') { + sentryPlugins.push(sentryOrchestrionPlugin({ buildTimeInstrumentation: mergedOptions.buildTimeInstrumentation })); + } + const sentryVitePluginsOptions = generateVitePluginOptions(mergedOptions); if (mergedOptions.autoUploadSourceMaps) { diff --git a/packages/sveltekit/test/vite/sentrySvelteKitPlugins.test.ts b/packages/sveltekit/test/vite/sentrySvelteKitPlugins.test.ts index eeb72b111ee5..586fb5906e48 100644 --- a/packages/sveltekit/test/vite/sentrySvelteKitPlugins.test.ts +++ b/packages/sveltekit/test/vite/sentrySvelteKitPlugins.test.ts @@ -17,6 +17,15 @@ vi.mock('fs', async () => { }; }); +// Stub the orchestrion plugin so these stay pure wiring tests (no apm code transformer pulled in). +// Mirror the real plugin's contract: `buildTimeInstrumentation: false` yields the inert variant. +const orchestrionVite = vi.fn((options?: { buildTimeInstrumentation?: boolean }) => ({ + name: options?.buildTimeInstrumentation === false ? 'sentry-orchestrion-disabled' : 'sentry-orchestrion-vite', +})); +vi.mock('@sentry/server-utils/orchestrion/vite', () => ({ + sentryOrchestrionPlugin: (options?: { buildTimeInstrumentation?: boolean }) => orchestrionVite(options), +})); + vi.spyOn(console, 'log').mockImplementation(() => { /* noop */ }); @@ -42,9 +51,9 @@ describe('sentrySvelteKit()', () => { const plugins = await getSentrySvelteKitPlugins(); expect(plugins).toBeInstanceOf(Array); - // 1 browser-tracing variant resolver + 1 auto instrument plugin + 1 global values injection plugin - // + 1 modified main plugin + 3 custom plugins - expect(plugins).toHaveLength(7); + // 1 browser-tracing variant resolver + 1 auto instrument plugin + 1 orchestrion plugin + // + 1 global values injection plugin + 1 modified main plugin + 3 custom plugins + expect(plugins).toHaveLength(8); }); it('returns the custom sentry source maps upload plugin, unmodified sourcemaps plugins and the auto-instrument plugin by default', async () => { @@ -55,6 +64,8 @@ describe('sentrySvelteKit()', () => { 'sentry-sveltekit-browser-tracing-variant', // auto instrument plugin: 'sentry-auto-instrumentation', + // orchestrion build-time instrumentation plugin: + 'sentry-orchestrion-vite', // global values injection plugin: 'sentry-sveltekit-global-values-injection-plugin', // modified main plugin (writeBundle deferred to closeBundle): @@ -68,7 +79,7 @@ describe('sentrySvelteKit()', () => { it("doesn't return the sentry source maps plugins if autoUploadSourcemaps is `false`", async () => { const plugins = await getSentrySvelteKitPlugins({ autoUploadSourceMaps: false }); - expect(plugins).toHaveLength(2); // browser-tracing variant resolver + auto instrument + expect(plugins).toHaveLength(3); // browser-tracing variant resolver + auto instrument + orchestrion }); it("doesn't return the sentry source maps plugins if `NODE_ENV` is development", async () => { @@ -78,7 +89,7 @@ describe('sentrySvelteKit()', () => { const plugins = await getSentrySvelteKitPlugins({ autoUploadSourceMaps: true, autoInstrument: true }); const instrumentPlugin = plugins[1]; - expect(plugins).toHaveLength(3); // browser-tracing variant resolver + auto instrument + global values injection + expect(plugins).toHaveLength(4); // browser-tracing variant resolver + auto instrument + orchestrion + global values injection expect(instrumentPlugin?.name).toEqual('sentry-auto-instrumentation'); process.env.NODE_ENV = previousEnv; @@ -87,10 +98,33 @@ describe('sentrySvelteKit()', () => { it("doesn't return the auto instrument plugin if autoInstrument is `false`", async () => { const plugins = await getSentrySvelteKitPlugins({ autoInstrument: false }); const pluginNames = plugins.map(plugin => plugin.name); - expect(plugins).toHaveLength(6); // browser-tracing variant resolver + global values injection + 1 modified main plugin + 3 custom plugins + expect(plugins).toHaveLength(7); // browser-tracing variant resolver + orchestrion + global values injection + 1 modified main plugin + 3 custom plugins expect(pluginNames).not.toContain('sentry-auto-instrumentation'); }); + it('adds the orchestrion plugin by default', async () => { + const plugins = await getSentrySvelteKitPlugins(); + expect(plugins.map(plugin => plugin.name)).toContain('sentry-orchestrion-vite'); + }); + + it('adds an inert orchestrion plugin when `buildTimeInstrumentation` is `false`', async () => { + orchestrionVite.mockClear(); + const plugins = await getSentrySvelteKitPlugins({ buildTimeInstrumentation: false }); + const pluginNames = plugins.map(plugin => plugin.name); + expect(orchestrionVite).toHaveBeenCalledWith({ buildTimeInstrumentation: false }); + expect(pluginNames).toContain('sentry-orchestrion-disabled'); + expect(pluginNames).not.toContain('sentry-orchestrion-vite'); + }); + + it("doesn't add the orchestrion plugin for the cloudflare adapter", async () => { + orchestrionVite.mockClear(); + const plugins = await getSentrySvelteKitPlugins({ adapter: 'cloudflare' }); + const pluginNames = plugins.map(plugin => plugin.name); + expect(orchestrionVite).not.toHaveBeenCalled(); + expect(pluginNames).not.toContain('sentry-orchestrion-vite'); + expect(pluginNames).not.toContain('sentry-orchestrion-disabled'); + }); + it('passes user-specified vite plugin options to the custom sentry source maps plugin', async () => { const makePluginSpy = vi.spyOn(sourceMaps, 'makeCustomSentryVitePlugins'); await getSentrySvelteKitPlugins({ From 4ac971e4e3386521bff703fb5b1d6c27eca5512e Mon Sep 17 00:00:00 2001 From: Charly Gomez Date: Tue, 28 Jul 2026 17:02:24 +0200 Subject: [PATCH 3/3] cloudflare comment --- packages/sveltekit/src/vite/sentryVitePlugins.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/sveltekit/src/vite/sentryVitePlugins.ts b/packages/sveltekit/src/vite/sentryVitePlugins.ts index df18ecb53283..7fb4312edf7a 100644 --- a/packages/sveltekit/src/vite/sentryVitePlugins.ts +++ b/packages/sveltekit/src/vite/sentryVitePlugins.ts @@ -55,9 +55,7 @@ export async function sentrySvelteKit(options: SentrySvelteKitPluginOptions = {} ); } - // Auto-instrument server-side dependencies at build time (mysql, ioredis, …) by injecting - // `diagnostics_channel` publishers. The plugin self-scopes to the SSR build and honors - // `buildTimeInstrumentation: false` itself. Cloudflare/workerd is not supported yet. + // TODO: Cloudflare needs different wiring if (mergedOptions.adapter !== 'cloudflare') { sentryPlugins.push(sentryOrchestrionPlugin({ buildTimeInstrumentation: mergedOptions.buildTimeInstrumentation })); }