Skip to content

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

Draft
JPeer264 wants to merge 4 commits into
developfrom
jp/orchestrion-cloudflare
Draft

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

Conversation

@JPeer264

@JPeer264 JPeer264 commented Jul 6, 2026

Copy link
Copy Markdown
Member

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({
  // The Sentry plugin runs first so its orchestrion transform injects the
  // `orchestrion:mysql:query` diagnostics channel into the bundled `mysql`
  // package before `@cloudflare/vite-plugin` finalizes the worker bundle.
- plugins: [cloudflare()],
+ plugins: [sentryCloudflareVitePlugin(), cloudflare()],
});

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 📦

⚠️ Warning: Base artifact is not the latest one, because the latest workflow run is not done yet. This may lead to incorrect results. Try to re-run all tests to get up to date results.

Path Size % Change Change
@sentry/browser 27.59 kB - -
@sentry/browser - with treeshaking flags 26.03 kB - -
@sentry/browser (incl. Tracing) 46.24 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 48.01 kB - -
@sentry/browser (incl. Tracing, Profiling) 51.01 kB - -
@sentry/browser (incl. Tracing, Replay) 85.49 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 75.1 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 90.19 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 102.84 kB - -
@sentry/browser (incl. Feedback) 44.76 kB - -
@sentry/browser (incl. sendFeedback) 32.38 kB - -
@sentry/browser (incl. FeedbackAsync) 37.51 kB - -
@sentry/browser (incl. Metrics) 28.67 kB - -
@sentry/browser (incl. Logs) 28.91 kB - -
@sentry/browser (incl. Metrics & Logs) 29.59 kB - -
@sentry/react 29.38 kB - -
@sentry/react (incl. Tracing) 48.51 kB - -
@sentry/vue 33.03 kB - -
@sentry/vue (incl. Tracing) 48.11 kB - -
@sentry/svelte 27.61 kB - -
CDN Bundle 30 kB - -
CDN Bundle (incl. Tracing) 48.24 kB - -
CDN Bundle (incl. Logs, Metrics) 31.57 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 49.54 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 70.77 kB - -
CDN Bundle (incl. Tracing, Replay) 85.7 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 87 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 91.49 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 92.78 kB - -
CDN Bundle - uncompressed 89.35 kB - -
CDN Bundle (incl. Tracing) - uncompressed 145.96 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 94.05 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 149.93 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 218.59 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 264.97 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 268.93 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 278.68 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 282.62 kB - -
@sentry/nextjs (client) 50.95 kB - -
@sentry/sveltekit (client) 46.65 kB - -
@sentry/core/server 78.38 kB - -
@sentry/core/browser 64.73 kB - -
@sentry/node-core 63.2 kB - -
@sentry/node 123.2 kB - -
@sentry/node/import (ESM hook with diagnostics-channel injection) 69.95 kB - -
@sentry/node/light 50.72 kB -0.01% -1 B 🔽
@sentry/node - without tracing 74.24 kB +0.01% +1 B 🔺
@sentry/aws-serverless 85.02 kB - -
⛔️ @sentry/cloudflare (withSentry) - minified (max: 215.04 kB) 228.01 kB +25.51% +46.33 kB 🔺
⛔️ @sentry/cloudflare (withSentry) (max: 522.24 kB) 556.9 kB +23.93% +107.51 kB 🔺

View base workflow run

JPeer264 and others added 4 commits July 6, 2026 15:08
…cted

Adds the orchestrion diagnostics-channel subscriber integrations (mysql,
pg, ...) from @sentry/server-utils to the Cloudflare SDK's default
integrations. They are only registered when the orchestrion bundler (or
runtime) marker is set, i.e. when the channels were actually injected
into the bundle - otherwise nothing ever publishes to them.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Exposes a Sentry Vite plugin for Cloudflare Workers that wraps the
orchestrion plugin from @sentry/server-utils. It injects diagnostics
channels into bundled npm packages (e.g. `mysql`) at build time, so the
SDK can trace them without monkey-patching - which wouldn't work in
workerd anyway, since there is no require hook to intercept module
loading.

The subpath is published ESM-only because
`@sentry/server-utils/orchestrion/vite` exposes no `require`
condition; Vite configs are ESM anyway.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Adds a worker that runs real `mysql` queries against a Dockerized
MySQL, built with Vite + `@cloudflare/vite-plugin` and the new
`@sentry/cloudflare/vite` plugin. The worker is wrapped manually with
`Sentry.withSentry`; the plugin only injects the orchestrion
diagnostics channel into the bundled `mysql` package.

The tests assert that the queries emit `db` spans with the
orchestrion-channel attributes on the request's http.server
transaction, including a query nested inside another query's callback
(i.e. across mysql's async socket-callback dispatch).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@JPeer264 JPeer264 force-pushed the jp/orchestrion-cloudflare branch from 9c5dcf0 to d99e2a7 Compare July 6, 2026 13:08
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.

1 participant