Skip to content

fix(cloudflare): Run build-time instrumentation in vite dev - #25777

Merged
Lms24 merged 2 commits into
jp/orchestrion-transform-sourcemap-sourcesfrom
jp/cloudflare-vite-dev-instrumentation
Oct 29, 2026
Merged

Lms24 merged 2 commits into
jp/orchestrion-transform-sourcemap-sourcesfrom
jp/cloudflare-vite-dev-instrumentation

Conversation

@JPeer264

@JPeer264 JPeer264 commented Oct 27, 2026 •

Copy link
Copy Markdown
Member

part of #25765
part of JS-4010

Description

This runs the orchestrion transform in the Vite dependency optimizer, so integrations that are added at build time (for example hono and graphql) also send spans in vite dev on Cloudflare. @cloudflare/vite-plugin pre-bundles the Worker dependencies into node_modules/.vite/deps_*, and before, the transform did not run on these files. The plugin adds a Rolldown plugin for Vite 8 and an esbuild plugin for Vite 6 and 7.

The new transformOptimizedDeps plugin option turns this on, and sentryCloudflareVitePlugin sets it. Node servers do not need it, because the runtime hook instruments the dependencies that Node loads.

The Cloudflare variant of the hono-4 e2e app now also runs its tests in vite dev.

Known issues

Sentry traces

Before (11.9.0), /graphql in vite dev, no graphql spans: https://sentry-sdks.sentry.io/explore/traces/trace/9221590d886f4648b401eded8a996046/
After, /graphql in vite dev, with graphql spans: https://sentry-sdks.sentry.io/explore/traces/trace/2aea20834d3d4fa38e39d37166273e14/
Before (11.9.0), /hono/users/1 in vite dev, span name GET /hono/users/1: https://sentry-sdks.sentry.io/explore/traces/trace/b8e5b8dba83b4b5aba45bdfdf40b307c/
After, /hono/users/1 in vite dev, span name GET /hono/users/:id from the Hono route: https://sentry-sdks.sentry.io/explore/traces/trace/20b2a5dcfe6a4dbfb7e68eb3037bf3b2/

@JPeer264
JPeer264 added this pull request to stack #25778 October 27, 2026 17:47
@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

size-limit report 📦

Compared: 6ba76e3 (PR test merge using develop at da369a5)

Against: 9c93bbd (develop) · base run #64212

⚠️ Baseline mismatch: 3 develop commit(s) in the PR build are missing from the baseline. Their size changes also affect this comparison. Compare commits. Re-run once develop's baseline build for da369a5 finishes.

Path Size % Change Change
@sentry/browser 30.39 kB - -
@sentry/browser - with treeshaking flags 28.53 kB - -
@sentry/browser - with treeshaking flags tracing without tracing 28.42 kB - -
@sentry/browser (incl. Tracing) 52.71 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 52.72 kB - -
@sentry/browser (incl. Tracing, Profiling) 55.69 kB - -
@sentry/browser (incl. Tracing, Replay) 93.01 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 81.61 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 97.76 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 110.75 kB - -
@sentry/browser (incl. Feedback) 47.97 kB - -
@sentry/browser (incl. sendFeedback) 35.49 kB - -
@sentry/browser (incl. FeedbackAsync) 40.6 kB - -
@sentry/browser (incl. Metrics) 31.42 kB - -
@sentry/browser (incl. Logs) 31.72 kB - -
@sentry/browser (incl. Metrics & Logs) 32.44 kB - -
@sentry/react 32.27 kB - -
@sentry/react (incl. Tracing) 55.07 kB - -
@sentry/vue 38.66 kB - -
@sentry/vue (incl. Tracing) 55.73 kB - -
@sentry/svelte 30.42 kB - -
@sentry/remix (Remix 3 client bundle) 57.8 kB - -
CDN Bundle 32.18 kB - -
CDN Bundle (incl. Tracing) 53.23 kB - -
CDN Bundle (incl. Logs, Metrics) 34.45 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 55.18 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 75.86 kB - -
CDN Bundle (incl. Tracing, Replay) 91.44 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 93.38 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 97.56 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 99.55 kB - -
CDN Bundle - uncompressed 94.62 kB - -
CDN Bundle (incl. Tracing) - uncompressed 157.6 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 101.09 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 163.33 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 232.65 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 279.29 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 285.01 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 292.99 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 298.7 kB - -
@sentry/nextjs (client) 57.89 kB - -
@sentry/sveltekit (client) 53.22 kB - -
@sentry/core/server 44.24 kB - -
@sentry/core/browser 13.93 kB - -
@sentry/node 154.92 kB +0.18% +269 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 81.95 kB +0.3% +243 B 🔺
@sentry/node - without tracing 96.13 kB +0.27% +251 B 🔺
@sentry/node - without channel injection 135.33 kB +0.02% +15 B 🔺
@sentry/aws-serverless 104.32 kB +0.26% +265 B 🔺
@sentry/cloudflare (withSentry) - minified 197.92 kB - -
@sentry/cloudflare (withSentry) 491.93 kB - -
@sentry/nextjs/cloudflare (withSentry) - minified 218.35 kB - -

View base workflow run

@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Optional E2E tests

Some optional checks were not successful. They do not block the merge. 1 not successful, 56 successful. See the run.

Check Status
❌ CI: Optional E2E Tests / E2E node-anthropic-send-to-sentry (latest) Test (optional) Failing after 4m Details
Successful checks
Check Status
✅ CI: Optional E2E Tests / E2E astro-7 Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nextjs-15 (latest) Test (optional) Successful in 3m Details
✅ CI: Optional E2E Tests / E2E nextjs-15 (turbo) Test (optional) Successful in 3m Details
✅ CI: Optional E2E Tests / E2E cloudflare-pi-durable (latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E deno (latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E cloudflare-think (ai v6) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nextjs-orpc Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E debug-id-sourcemaps Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E cloudflare-agent Test (optional) Successful in 26s Details
✅ CI: Optional E2E Tests / E2E react-send-to-sentry Test (optional) Successful in 3m Details
✅ CI: Optional E2E Tests / E2E tanstackstart-react-sourcemaps Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E gen-ai-libraries (cloudflare) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nextjs-16 (vinext) Test (optional) Successful in 3m Details
✅ CI: Optional E2E Tests / E2E cloudflare-think Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E astro-7-static Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nextjs-16-tunnel (cloudflare) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-openai-decisions (latest) Test (optional) Successful in 29s Details
✅ CI: Optional E2E Tests / E2E cloudflare-workers-send-to-sentry Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E nextjs-16 (deno) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E node-eve (orchestrion) Test (optional) Successful in 47s Details
✅ CI: Optional E2E Tests / E2E react-router-7-framework-instrumentation Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E node-anthropic-send-to-sentry Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nuxt-5-sourcemaps (static / nuxt generate) Test (optional) Successful in 36s Details
✅ CI: Optional E2E Tests / E2E cloudflare-flue-send-to-sentry Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-openai-send-to-sentry Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E gen-ai-libraries Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nestjs-12 (latest) Test (optional) Successful in 35s Details
✅ CI: Optional E2E Tests / E2E node-pi-durable Test (optional) Successful in 35s Details
✅ CI: Optional E2E Tests / E2E cloudflare-mastra Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-express-send-to-sentry-static Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-flue (latest) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E node-eve Test (optional) Successful in 43s Details
✅ CI: Optional E2E Tests / E2E node-mastra (latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-fastify-6 Test (optional) Successful in 20s Details
✅ CI: Optional E2E Tests / E2E nuxt-5-sourcemaps (client source maps kept) Test (optional) Successful in 37s Details
✅ CI: Optional E2E Tests / E2E node-express-mcp-v1 Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nextjs-16 (cloudflare, latest) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E nextjs-16 (vinext, bun) Test (optional) Successful in 3m Details
✅ CI: Optional E2E Tests / E2E node-pi-durable (latest) Test (optional) Successful in 26s Details
✅ CI: Optional E2E Tests / E2E cloudflare-pi-durable Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-fastify-6 (tracer provider) Test (optional) Successful in 22s Details
✅ CI: Optional E2E Tests / E2E node-express-mcp-v2 Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-openai-send-to-sentry (latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nextjs-14 (latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-mastra Test (optional) Successful in 45s Details
✅ CI: Optional E2E Tests / E2E tanstackstart-react (latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E supabase-nextjs Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E nuxt-5-sourcemaps Test (optional) Successful in 27s Details
✅ CI: Optional E2E Tests / E2E nuxt-5 Test (optional) Successful in 3m Details
✅ CI: Optional E2E Tests / E2E node-express-send-to-sentry Test (optional) Successful in 54s Details
✅ CI: Optional E2E Tests / E2E node-flue Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E tanstackstart-react-cloudflare Test (optional) Successful in 27s Details
✅ CI: Optional E2E Tests / E2E node-openai-decisions Test (optional) Successful in 18s Details
✅ CI: Optional E2E Tests / E2E node-eve (latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E vue-3 (no Options API) Test (optional) Successful in 57s Details
✅ CI: Optional E2E Tests / E2E solidstart-2 Test (optional) Successful in 2m Details

@isaacs isaacs left a comment

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.

The design is sound for its target. The main problem is scope. It applies to every server environment of every SDK that uses the shared Vite plugin, not only cloudflare.

Comment on lines +92 to +94
if (isDuplicate()) {
return;
}

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.

This is function is gonna cause a crash if it's used in a node bundle with vite.

On Vite 6 and 7, the dependency optimizer uses platform: 'node' for any server environment that is not webworker (the default ssr environment of every Node SSR framework). For that platform, Vite adds this banner to every optimized file:

import { createRequire } from 'module';const require = createRequire(import.meta.url);

The new esbuild plugin makes the optimizer bundle @sentry/server-utils (and @sentry/core) into the pre-bundled dependency.

Two lines in depOptimizerEsbuildPlugin cause this. Line 112 (upstream.setup(build)) adds the transform, which puts an import of @sentry/server-utils into each instrumented module. Line 107 then resolves that import to a file path (toEsmEntry(resolved.path)), so esbuild bundles the file instead of leaving the import external. The @sentry/server-utils ESM build has its own top-level import { createRequire } from "module", and esbuild cannot rename around a text banner. The result is a file that doesn't parse:

vite 6.4.3 esm  load error: Identifier 'createRequire' has already been declared
vite 6.4.3 cjs  load error: Identifier 'createRequire' has already been declared
vite 7.3.6 esm  load error: Identifier 'createRequire' has already been declared
vite 7.3.6 cjs  load error: Identifier 'createRequire' has already been declared
vite 8.3.1 esm  runs: x channel fired: true
vite 8.3.1 cjs  runs: x channel fired: true

Cloudflare is not affected, because @cloudflare/vite-plugin sets platform: 'neutral', which has no banner. With platform: 'neutral' the Vite 6/7 ESM case loads and fires the channel.

Suggestion: scope the dev optimizer plugins to the case this PR targets. Two options:

  1. Minimal: don't register the resolver or the transform when the optimizer bundles for Node. Vite passes the platform it picked to esbuild as build.initialOptions.platform, so setup (line 91) can return before it reaches lines 96-112. The existing duplicate-instance check here already returns early in the same place, so the new check can go next to it:
Suggested change
if (isDuplicate()) {
return;
}
// Vite 6/7 add a `createRequire` banner for `platform: 'node'`, which
// collides with the `createRequire` import in the bundled SDK.
if (build.initialOptions.platform === 'node') {
return;
}
if (isDuplicate()) {
return;
}
  1. Cleaner: add an opt-in option to PluginOptions that sentryCloudflareVitePlugin sets, so the other SDKs keep today's serve behavior. The PR title says fix(cloudflare), and the comment at lines 205-207 names @cloudflare/vite-plugin as the reason. An opt-in would make the change match that scope. It would also avoid the side effects on Node SSR envs. This option touches three places: the new field in PluginOptions (packages/server-utils/src/orchestrion/bundler/options.ts), the serve branch at line 208 of vite.ts (return null when the option is off), and the sentryOrchestrionPlugin({ ... }) call at packages/cloudflare/src/vite/index.ts line 88.

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.

I'm gonna check. I like the opt-in method.

const plugin = vitePlugin();
// Vite 6 passes no context, Vite 8 passes `rolldownVersion`.
context?: { meta: { rolldownVersion?: string } },
plugin = vitePlugin(),

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.

nit: this now takes 5 positional parameters. Might be time for an options object?

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.

Yeah that's actually better! I'll change it

@JPeer264
JPeer264 marked this pull request as ready for review October 27, 2026 22:10
@JPeer264
JPeer264 requested a review from a team as a code owner October 27, 2026 22:11
@JPeer264
JPeer264 requested review from andreiborza, isaacs and mydea and removed request for a team and mydea October 27, 2026 22:11
@JPeer264

Copy link
Copy Markdown
Member Author

The main problem is scope. It applies to every server environment of every SDK that uses the shared Vite plugin, not only cloudflare.

Good that you brought that up. I actually assumed there might be cases where it is applicable in Node as well. Since on plain Vite+Node it's already working we can do the opt-in as you suggested.

@JPeer264
JPeer264 removed the request for review from andreiborza October 28, 2026 14:30
@Lms24
Lms24 requested review from a team as code owners October 29, 2026 16:06
@Lms24
Lms24 requested review from chargome, logaretm, msonnb and nicohrubec and removed request for a team October 29, 2026 16:06
@Lms24
Lms24 force-pushed the jp/cloudflare-vite-dev-instrumentation branch from 76f66b4 to 02226bf Compare October 29, 2026 16:06
JPeer264 and others added 2 commits October 29, 2026 18:25
`@cloudflare/vite-plugin` pre-bundles the worker dependencies in `vite dev`,
and the Vite dependency optimizer runs no Vite plugins. So the orchestrion
transform never ran on instrumented packages, and their spans were missing.

The orchestrion Vite plugin now adds the transform to `optimizeDeps` of
server environments in `serve`: a Rolldown plugin on Vite 8 and an esbuild
plugin on Vite 6 and 7. Both resolve the snippet import to the ESM entry of
`@sentry/server-utils`, like the build does.

The cloudflare variant of the `hono-4` e2e app now also runs its tests
against `vite dev`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Lms24
Lms24 force-pushed the jp/cloudflare-vite-dev-instrumentation branch from 02226bf to 5a5f947 Compare October 29, 2026 17:26
@Lms24
Lms24 merged commit 30cfb4c into develop Oct 29, 2026
373 of 404 checks passed
@Lms24
Lms24 deleted the jp/cloudflare-vite-dev-instrumentation branch October 29, 2026 17:38
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.

3 participants