Skip to content

feat(cloudflare): Add @sentry/cloudflare/vite orchestrion plugin #21967

Open
JPeer264 wants to merge 2 commits into
jp/orchestrion-integrationsfrom
jp/orchestrion-cloudflare
Open

feat(cloudflare): Add @sentry/cloudflare/vite orchestrion plugin #21967
JPeer264 wants to merge 2 commits into
jp/orchestrion-integrationsfrom
jp/orchestrion-cloudflare

Conversation

@JPeer264

@JPeer264 JPeer264 commented Jul 6, 2026

Copy link
Copy Markdown
Member

closes #22062

This adds a /vite plugin for Cloudflare that adds Orchestrion on build time. It adds all orchestrion integrations in the defaultIntegrations, which adds more bundle size - this is not optimal and will be adapted in a follow up PR. Best case scenario: Only add integrations which the user really installed.

For now the user only has to add the following to the Vite config:

import { cloudflare } from '@cloudflare/vite-plugin';
+ import { sentryCloudflareVitePlugin } from '@sentry/cloudflare/vite';
import { defineConfig } from 'vite';

export default defineConfig({
- plugins: [cloudflare()],
+ plugins: [
+   cloudflare(),
+   sentryCloudflareVitePlugin({
+     _experimental: {
+       useDiagnosticsChannelInjection: true,
+     }
+   })
+ ],
});

The _experimental.useDiagnosticsChannelInjection is the same as we have in Next.js via the Webpack plugin - so it stays consistent

Also the migration from pure wrangler to Vite is as easy as just adding vite.config.ts and prepending vite build before wrangler deploy: https://developers.cloudflare.com/workers/vite-plugin/reference/migrating-from-wrangler-dev/

@JPeer264 JPeer264 self-assigned this Jul 6, 2026
@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 27.74 kB - -
@sentry/browser - with treeshaking flags 26.19 kB - -
@sentry/browser (incl. Tracing) 46.57 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 48.36 kB - -
@sentry/browser (incl. Tracing, Profiling) 51.34 kB - -
@sentry/browser (incl. Tracing, Replay) 85.83 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 75.47 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 90.55 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 103.19 kB - -
@sentry/browser (incl. Feedback) 44.92 kB - -
@sentry/browser (incl. sendFeedback) 32.54 kB - -
@sentry/browser (incl. FeedbackAsync) 37.67 kB - -
@sentry/browser (incl. Metrics) 28.84 kB - -
@sentry/browser (incl. Logs) 29.07 kB - -
@sentry/browser (incl. Metrics & Logs) 29.76 kB - -
@sentry/react 29.54 kB - -
@sentry/react (incl. Tracing) 48.82 kB - -
@sentry/vue 33.17 kB - -
@sentry/vue (incl. Tracing) 48.55 kB - -
@sentry/svelte 27.77 kB - -
CDN Bundle 30.14 kB - -
CDN Bundle (incl. Tracing) 48.52 kB - -
CDN Bundle (incl. Logs, Metrics) 31.72 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 49.83 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 70.97 kB - -
CDN Bundle (incl. Tracing, Replay) 86.04 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 87.33 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 91.82 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 93.1 kB - -
CDN Bundle - uncompressed 89.85 kB - -
CDN Bundle (incl. Tracing) - uncompressed 146.66 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 94.56 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 150.64 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 219.29 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 265.87 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 269.84 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 279.57 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 283.53 kB - -
@sentry/nextjs (client) 51.38 kB - -
@sentry/sveltekit (client) 47 kB - -
@sentry/core/server 78.71 kB - -
@sentry/core/browser 65.08 kB - -
@sentry/node-core 63.2 kB -0.01% -1 B 🔽
@sentry/node 125.54 kB -0.01% -1 B 🔽
@sentry/node (incl. diagnostics channel injection) 148.38 kB +0.2% +284 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 70.03 kB - -
@sentry/node/light 51.33 kB -0.01% -1 B 🔽
@sentry/node - without tracing 74.7 kB -0.01% -2 B 🔽
@sentry/aws-serverless 83.92 kB - -
@sentry/cloudflare (withSentry) - minified 182.25 kB +0.09% +148 B 🔺
@sentry/cloudflare (withSentry) 451.64 kB +0.17% +741 B 🔺

View base workflow run

@JPeer264
JPeer264 force-pushed the jp/orchestrion-cloudflare branch 8 times, most recently from 18b7454 to 596608d Compare July 13, 2026 09:48
@JPeer264
JPeer264 changed the base branch from develop to jp/orchestrion-integrations July 13, 2026 12:53
@JPeer264
JPeer264 force-pushed the jp/orchestrion-cloudflare branch from 596608d to f5c454b Compare July 13, 2026 13:08
@JPeer264
JPeer264 force-pushed the jp/orchestrion-integrations branch from 4d78130 to b66e928 Compare July 14, 2026 13:26
@JPeer264
JPeer264 force-pushed the jp/orchestrion-cloudflare branch from 515173e to 45a679c Compare July 14, 2026 13:32
@JPeer264
JPeer264 force-pushed the jp/orchestrion-integrations branch from b66e928 to 332ece3 Compare July 14, 2026 14:44
@JPeer264
JPeer264 force-pushed the jp/orchestrion-cloudflare branch from 45a679c to 6e6c5b7 Compare July 14, 2026 14:44
@JPeer264
JPeer264 force-pushed the jp/orchestrion-integrations branch 4 times, most recently from baafdd8 to 931a37a Compare July 15, 2026 07:30
@JPeer264
JPeer264 force-pushed the jp/orchestrion-cloudflare branch from 6e6c5b7 to d6c0992 Compare July 15, 2026 08:56
@JPeer264
JPeer264 force-pushed the jp/orchestrion-integrations branch from 95c6874 to c0dfebc Compare July 15, 2026 09:20
@JPeer264
JPeer264 force-pushed the jp/orchestrion-cloudflare branch 4 times, most recently from 4da617b to 965040a Compare July 15, 2026 09:43
@JPeer264

Copy link
Copy Markdown
Member Author

bugbot run

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 965040a. Configure here.

@JPeer264
JPeer264 force-pushed the jp/orchestrion-cloudflare branch 2 times, most recently from c7a4227 to f750c0d Compare July 15, 2026 10:50
@JPeer264
JPeer264 marked this pull request as ready for review July 15, 2026 10:51
@JPeer264
JPeer264 requested a review from a team as a code owner July 15, 2026 10:51
@JPeer264
JPeer264 requested review from andreiborza, isaacs, mydea and timfish and removed request for a team July 15, 2026 10:51
@JPeer264
JPeer264 force-pushed the jp/orchestrion-integrations branch from b341ad9 to 06971c5 Compare July 15, 2026 10:59
@JPeer264
JPeer264 requested a review from a team as a code owner July 15, 2026 10:59
@JPeer264
JPeer264 force-pushed the jp/orchestrion-cloudflare branch 2 times, most recently from 2a66913 to 7249eff Compare July 15, 2026 11:16
@JPeer264
JPeer264 force-pushed the jp/orchestrion-integrations branch from e7262f3 to 6713fc3 Compare July 15, 2026 11:38
@JPeer264
JPeer264 force-pushed the jp/orchestrion-cloudflare branch from 7249eff to afcb71d Compare July 15, 2026 11:38
Comment on lines +51 to +52
"types": "./build/types/vite/index.d.ts",
"import": "./build/esm/vite/index.js"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't you need the cjs export here as well? Other exports have it 👀

Edit: I just noticed the comment above that it's only ESM. But this PR could fix that: #22286

Comment on lines +8 to +12
sentryCloudflareVitePlugin({
_experimental: {
useDiagnosticsChannelInjection: true,
},
}),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the only option that would be needed to enable this?

Asking because usually, there's still the Sentry.experimentalUseDiagnosticsChannelInjection(); before init (while we're on v10).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. experimentalUseDiagnosticsChannelInjection wouldn't have an effect right now, because the Cloudflare SDK is using the core client and not the one from the Node SDK.

That would only change if we move this entire snippet over to Cloudflare directly:

...diagnosticsChannelInjection.integrations,

@JPeer264
JPeer264 force-pushed the jp/orchestrion-integrations branch from 6713fc3 to 0d56181 Compare July 16, 2026 06:39
@JPeer264
JPeer264 force-pushed the jp/orchestrion-cloudflare branch 2 times, most recently from 8517822 to 7e8f420 Compare July 16, 2026 07:34
Comment thread packages/cloudflare/src/sdk.ts Outdated
Comment on lines +29 to +34
*/
function getRegisteredChannelIntegrations(): Integration[] {
const marker = GLOBAL_OBJ.__SENTRY_ORCHESTRION__;
const registered = marker?.integrations || [];

return registered.map(factory => factory());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The bundler property on globalThis.__SENTRY_ORCHESTRION__ is typed as string[] but is set to a boolean true by the Vite plugin, creating a type inconsistency.
Severity: LOW

Suggested Fix

To ensure type consistency, the Vite plugin should be updated to set globalThis.__SENTRY_ORCHESTRION__.bundler to a value that matches its string[] type. For example, instead of true, it could be set to an empty array [] or a specific marker array like ['vite'] if that information is useful for debugging.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: packages/cloudflare/src/sdk.ts#L29-L34

Potential issue: A type mismatch exists for the `bundler` property on the global
`__SENTRY_ORCHESTRION__` object. The property is typed as `string[]` in `worldwide.ts`,
but the Vite plugin introduced in this pull request sets it to a boolean value (`true`).
While the current runtime usage only checks for truthiness, which works for both types,
this inconsistency violates the established type contract. This could lead to future
runtime errors if other code is added that expects `bundler` to be an array and attempts
to use array methods on it. The mismatch creates a type safety issue that should be
corrected for code consistency and to prevent potential future bugs.

Also affects:

  • packages/cloudflare/src/vite/index.ts:35~35

Did we get this right? 👍 / 👎 to inform future reviews.

@JPeer264
JPeer264 force-pushed the jp/orchestrion-integrations branch from b59ebba to 157e383 Compare July 17, 2026 06:57
@JPeer264
JPeer264 force-pushed the jp/orchestrion-cloudflare branch from cfc41ca to d2a6c9f Compare July 17, 2026 06:57
Comment thread packages/cloudflare/test/sdk.test.ts Outdated
JPeer264 and others added 2 commits July 17, 2026 09:12
…tics channels

Integrate the server-utils orchestrion channel-integration mechanism into the
Cloudflare SDK, so bundled npm packages (e.g. `mysql`) are traced without
monkey-patching, which workerd doesn't support anyway.

- Add the `@sentry/cloudflare/vite` plugin, which runs the orchestrion transform
  (injecting `diagnostics_channel.tracingChannel` calls) and injects a
  registration module that puts the channel-subscriber integrations on the
  global marker. Workers built without the plugin don't ship that code.
- `getDefaultIntegrations()` reads the registered integrations from the marker
  at `init()`, activating only those whose module was actually transformed, and
  warns (debug only, once per isolate) about modules whose transform failed.
- Add a Cloudflare + MySQL e2e test app exercising real `db` spans in workerd.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…tics channels

Integrate the server-utils orchestrion channel-integration mechanism into the
Cloudflare SDK, so bundled npm packages (e.g. `mysql`) are traced without
monkey-patching, which workerd doesn't support anyway.

- Add the `@sentry/cloudflare/vite` plugin, which runs the orchestrion transform
  (injecting `diagnostics_channel.tracingChannel` calls) and injects a
  registration module that puts the channel-subscriber integrations on the
  global marker. Workers built without the plugin don't ship that code.
- `getDefaultIntegrations()` reads the registered integrations from the marker
  at `init()`, activating only those whose module was actually transformed, and
  warns (debug only, once per isolate) about modules whose transform failed.
- Add a Cloudflare + MySQL e2e test app exercising real `db` spans in workerd.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@JPeer264
JPeer264 force-pushed the jp/orchestrion-integrations branch from 157e383 to 6755627 Compare July 17, 2026 07:21
@JPeer264
JPeer264 force-pushed the jp/orchestrion-cloudflare branch from d2a6c9f to dbd5795 Compare July 17, 2026 07:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add more instrumentation with Orchestrion

2 participants