From 70d7e7a916859b184aaf63969dfe4a46c3e324df Mon Sep 17 00:00:00 2001 From: Charly Gomez Date: Mon, 3 Aug 2026 14:15:32 +0200 Subject: [PATCH 1/3] feat(cloudflare)!: Enable build-time instrumentation by default in Vite plugin Enables orchestrion build-time instrumentation by default in the @sentry/cloudflare Vite plugin, matching the other metaframework SDKs. sentryCloudflareVitePlugin() now instruments supported dependencies (e.g. mysql) with zero config; opt out via buildTimeInstrumentation: false. Replaces the experimental _experimental.useDiagnosticsChannelInjection flag. Ref: getsentry/sentry-javascript#22764 Co-Authored-By: Claude Opus 4.8 --- .../vite.config.ts | 9 +--- packages/cloudflare/src/vite/index.ts | 52 ++++++++----------- 2 files changed, 23 insertions(+), 38 deletions(-) diff --git a/dev-packages/e2e-tests/test-applications/cloudflare-orchestrion-mysql/vite.config.ts b/dev-packages/e2e-tests/test-applications/cloudflare-orchestrion-mysql/vite.config.ts index 541d36ac0a61..005f4448f6cb 100644 --- a/dev-packages/e2e-tests/test-applications/cloudflare-orchestrion-mysql/vite.config.ts +++ b/dev-packages/e2e-tests/test-applications/cloudflare-orchestrion-mysql/vite.config.ts @@ -3,12 +3,5 @@ import { sentryCloudflareVitePlugin } from '@sentry/cloudflare/vite'; import { defineConfig } from 'vite'; export default defineConfig({ - plugins: [ - cloudflare(), - sentryCloudflareVitePlugin({ - _experimental: { - useDiagnosticsChannelInjection: true, - }, - }), - ], + plugins: [cloudflare(), sentryCloudflareVitePlugin()], }); diff --git a/packages/cloudflare/src/vite/index.ts b/packages/cloudflare/src/vite/index.ts index 035ce9b3e4ec..f611748d9aec 100644 --- a/packages/cloudflare/src/vite/index.ts +++ b/packages/cloudflare/src/vite/index.ts @@ -21,25 +21,24 @@ export interface SentryCloudflareVitePluginOptions { * @default undefined (probes `wrangler.json`, `wrangler.jsonc`, `wrangler.toml` at the Vite root) */ wranglerConfigPath?: string; + /** + * Build-time automatic instrumentation of supported dependencies (e.g. + * database clients like `mysql`) so the Sentry Cloudflare SDK can trace them + * without monkey-patching, which wouldn't work in workerd anyway. + * + * When enabled, the plugin injects `diagnostics_channel.tracingChannel` calls + * into the bundled packages and, next to each, a snippet that registers the + * matching Sentry channel-subscriber factory on the global marker, which the + * SDK picks up in `Sentry.withSentry()`. Both `vite build` and `vite dev` are + * instrumented. Set to `false` to opt out. + * + * @default true + */ + buildTimeInstrumentation?: boolean; /** * Experimental options that may change or be removed without notice. */ _experimental?: { - /** - * Enables build-time automatic instrumentation of supported dependencies - * (e.g. database clients like `mysql`) so the Sentry Cloudflare SDK can - * trace them without monkey-patching, which wouldn't work in workerd anyway. - * - * When enabled, the plugin injects `diagnostics_channel.tracingChannel` - * calls into the bundled packages and, next to each, a snippet that - * registers the matching Sentry channel-subscriber factory on the global - * marker, which the SDK picks up in `Sentry.withSentry()`. Both `vite build` - * and `vite dev` are instrumented. - * - * @default false - * @experimental May change or be removed in any release. - */ - useDiagnosticsChannelInjection?: boolean; /** * Automatically wraps your Worker at build time so you don't have to edit * your entry: the plugin reads your wrangler config, wraps the default @@ -62,10 +61,9 @@ export interface SentryCloudflareVitePluginOptions { * instrumentation for Cloudflare Workers built with Vite. Configure the Sentry * SDK in your Worker as usual with `Sentry.withSentry()`. * - * Currently, the only functionality is the experimental - * `_experimental.useDiagnosticsChannelInjection` option, which traces supported - * dependencies (such as database clients) without changing your application - * code. Without it, the plugin is a no-op. + * By default, the plugin build-time instruments supported dependencies (such as + * database clients) so they are traced without changing your application code. + * Opt out with `buildTimeInstrumentation: false`. * * @example * ```ts @@ -75,22 +73,16 @@ export interface SentryCloudflareVitePluginOptions { * import { defineConfig } from 'vite'; * * export default defineConfig({ - * plugins: [ - * cloudflare(), - * sentryCloudflareVitePlugin({ - * _experimental: { - * useDiagnosticsChannelInjection: true, - * }, - * }), - * ], + * plugins: [cloudflare(), sentryCloudflareVitePlugin()], * }); * ``` */ export function sentryCloudflareVitePlugin(options: SentryCloudflareVitePluginOptions = {}) { return [ - ...(options._experimental?.useDiagnosticsChannelInjection - ? [sentryOrchestrionPlugin({ injectChannelSubscribers: true })] - : []), + sentryOrchestrionPlugin({ + injectChannelSubscribers: true, + buildTimeInstrumentation: options.buildTimeInstrumentation, + }), ...(options._experimental?.autoInstrumentation ? [sentryCloudflareAutoInstrumentPlugin({ wranglerConfigPath: options.wranglerConfigPath })] : []), From 7c6d5d15b9e7cadbee05b3e2c7bb5fdd258f2655 Mon Sep 17 00:00:00 2001 From: Charly Gomez Date: Mon, 3 Aug 2026 15:28:01 +0200 Subject: [PATCH 2/3] typecheck --- .../client-build/vite.config.mts | 14 -------------- .../client-build/vite.config.ts | 10 ++++++++++ 2 files changed, 10 insertions(+), 14 deletions(-) delete mode 100644 dev-packages/cloudflare-integration-tests/suites/vite/diagnostics-channel/client-build/vite.config.mts create mode 100644 dev-packages/cloudflare-integration-tests/suites/vite/diagnostics-channel/client-build/vite.config.ts diff --git a/dev-packages/cloudflare-integration-tests/suites/vite/diagnostics-channel/client-build/vite.config.mts b/dev-packages/cloudflare-integration-tests/suites/vite/diagnostics-channel/client-build/vite.config.mts deleted file mode 100644 index 541d36ac0a61..000000000000 --- a/dev-packages/cloudflare-integration-tests/suites/vite/diagnostics-channel/client-build/vite.config.mts +++ /dev/null @@ -1,14 +0,0 @@ -import { cloudflare } from '@cloudflare/vite-plugin'; -import { sentryCloudflareVitePlugin } from '@sentry/cloudflare/vite'; -import { defineConfig } from 'vite'; - -export default defineConfig({ - plugins: [ - cloudflare(), - sentryCloudflareVitePlugin({ - _experimental: { - useDiagnosticsChannelInjection: true, - }, - }), - ], -}); diff --git a/dev-packages/cloudflare-integration-tests/suites/vite/diagnostics-channel/client-build/vite.config.ts b/dev-packages/cloudflare-integration-tests/suites/vite/diagnostics-channel/client-build/vite.config.ts new file mode 100644 index 000000000000..58338f28340b --- /dev/null +++ b/dev-packages/cloudflare-integration-tests/suites/vite/diagnostics-channel/client-build/vite.config.ts @@ -0,0 +1,10 @@ +import { cloudflare } from '@cloudflare/vite-plugin'; +import { sentryCloudflareVitePlugin } from '@sentry/cloudflare/vite'; +import { defineConfig, type PluginOption } from 'vite'; + +export default defineConfig({ + // The `as PluginOption` cast fixes an overload error from two Vite + // versions resolving in the workspace (root vs vitest's nested copy); the plugin + // options object is still type-checked at the call site. + plugins: [cloudflare(), sentryCloudflareVitePlugin() as PluginOption], +}); From 02a51c5531377888a52c19e6729e37a1bcff29bd Mon Sep 17 00:00:00 2001 From: Charly Gomez Date: Mon, 3 Aug 2026 15:57:00 +0200 Subject: [PATCH 3/3] test(cloudflare): Keep diagnostics-channel vite config as .mts Renaming to .ts broke the build: `@cloudflare/vite-plugin` is ESM-only and a `.ts` vite config is loaded via `require` here, so the extension must stay `.mts`. Drop only the now-removed `_experimental.useDiagnosticsChannelInjection` option; typecheck coverage for `.mts` configs is a separate follow-up. Co-Authored-By: Claude Opus 4.8 --- .../diagnostics-channel/client-build/vite.config.mts | 7 +++++++ .../diagnostics-channel/client-build/vite.config.ts | 10 ---------- 2 files changed, 7 insertions(+), 10 deletions(-) create mode 100644 dev-packages/cloudflare-integration-tests/suites/vite/diagnostics-channel/client-build/vite.config.mts delete mode 100644 dev-packages/cloudflare-integration-tests/suites/vite/diagnostics-channel/client-build/vite.config.ts diff --git a/dev-packages/cloudflare-integration-tests/suites/vite/diagnostics-channel/client-build/vite.config.mts b/dev-packages/cloudflare-integration-tests/suites/vite/diagnostics-channel/client-build/vite.config.mts new file mode 100644 index 000000000000..005f4448f6cb --- /dev/null +++ b/dev-packages/cloudflare-integration-tests/suites/vite/diagnostics-channel/client-build/vite.config.mts @@ -0,0 +1,7 @@ +import { cloudflare } from '@cloudflare/vite-plugin'; +import { sentryCloudflareVitePlugin } from '@sentry/cloudflare/vite'; +import { defineConfig } from 'vite'; + +export default defineConfig({ + plugins: [cloudflare(), sentryCloudflareVitePlugin()], +}); diff --git a/dev-packages/cloudflare-integration-tests/suites/vite/diagnostics-channel/client-build/vite.config.ts b/dev-packages/cloudflare-integration-tests/suites/vite/diagnostics-channel/client-build/vite.config.ts deleted file mode 100644 index 58338f28340b..000000000000 --- a/dev-packages/cloudflare-integration-tests/suites/vite/diagnostics-channel/client-build/vite.config.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { cloudflare } from '@cloudflare/vite-plugin'; -import { sentryCloudflareVitePlugin } from '@sentry/cloudflare/vite'; -import { defineConfig, type PluginOption } from 'vite'; - -export default defineConfig({ - // The `as PluginOption` cast fixes an overload error from two Vite - // versions resolving in the workspace (root vs vitest's nested copy); the plugin - // options object is still type-checked at the call site. - plugins: [cloudflare(), sentryCloudflareVitePlugin() as PluginOption], -});