Skip to content

feat(cloudflare): Answer managed tunnel requests in withSentry - #25999

Open
logaretm wants to merge 4 commits into
awad/runtime-tunnel-node-bun-denofrom
awad/runtime-tunnel-cloudflare
Open

logaretm wants to merge 4 commits into
awad/runtime-tunnel-node-bun-denofrom
awad/runtime-tunnel-cloudflare

Conversation

@logaretm

@logaretm logaretm commented Nov 2, 2026 •

Copy link
Copy Markdown
Member

Adds the tunnel handling logic to our CF workers wrapper, and re-wires astro and other CF capable frameworks.

Note for reviewers: if you are lacking context on this PR, check #25997

@logaretm
logaretm added this pull request to stack #26002 November 2, 2026 19:44
@github-actions

github-actions Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

size-limit report 📦

Compared: 1274d44 (PR test merge using develop at dcc7e5e)

Against: 3963e60 (develop) · base run #65264

⚠️ Baseline mismatch: 29 develop commit(s) in the PR build are missing from the baseline; 7 develop commit(s) in the baseline are missing from the PR build. Their size changes also affect this comparison. Compare commits. Rebase your PR onto the latest develop to compare against an up-to-date baseline.

Path Size % Change Change
@sentry/browser 29.92 kB - -
@sentry/browser - with treeshaking flags 28.08 kB - -
@sentry/browser - with treeshaking flags tracing without tracing 27.97 kB - -
@sentry/browser (incl. Tracing) 52.2 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 52.22 kB - -
@sentry/browser (incl. Tracing, Profiling) 55.18 kB - -
@sentry/browser (incl. Tracing, Replay) 92.52 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 81.2 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 97.25 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 110.25 kB - -
@sentry/browser (incl. Feedback) 47.52 kB - -
@sentry/browser (incl. sendFeedback) 35.02 kB - -
@sentry/browser (incl. FeedbackAsync) 40.13 kB - -
@sentry/browser (incl. Metrics) 31.48 kB - -
@sentry/browser (incl. Logs) 31.77 kB - -
@sentry/browser (incl. Metrics & Logs) 32.45 kB - -
@sentry/react 31.78 kB - -
@sentry/react (incl. Tracing) 54.62 kB - -
@sentry/vue 38.24 kB - -
@sentry/vue (incl. Tracing) 55.24 kB - -
@sentry/svelte 29.95 kB - -
@sentry/remix (Remix 3 client bundle) 57.83 kB - -
CDN Bundle 31.72 kB - -
CDN Bundle (incl. Tracing) 52.81 kB - -
CDN Bundle (incl. Logs, Metrics) 34.52 kB +0.01% +3 B 🔺
CDN Bundle (incl. Tracing, Logs, Metrics) 55.32 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 75.9 kB - -
CDN Bundle (incl. Tracing, Replay) 90.98 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 93.54 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 97.11 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 99.71 kB - -
CDN Bundle - uncompressed 92.76 kB - -
CDN Bundle (incl. Tracing) - uncompressed 155.77 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 101.29 kB -0.01% -2 B 🔽
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 163.55 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 232.85 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 277.46 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 285.23 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 291.17 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 298.92 kB - -
@sentry/nextjs (client) 57.64 kB +0.02% +8 B 🔺
@sentry/sveltekit (client) 52.73 kB - -
@sentry/core/server 44.17 kB +0.82% +356 B 🔺
@sentry/core/browser 13.93 kB - -
@sentry/node 156.95 kB +0.15% +229 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 82.28 kB +0.01% +1 B 🔺
@sentry/node - without tracing 96.92 kB +0.34% +325 B 🔺
@sentry/node - without channel injection 137.24 kB +0.15% +201 B 🔺
@sentry/aws-serverless 105.52 kB +0.25% +254 B 🔺
@sentry/cloudflare (withSentry) - minified 201.54 kB +0.73% +1.45 kB 🔺
@sentry/cloudflare (withSentry) 500.16 kB +0.62% +3.06 kB 🔺
@sentry/nextjs/cloudflare (withSentry) - minified 223.4 kB +0.66% +1.45 kB 🔺

View base workflow run

@github-actions

github-actions Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Optional E2E tests

Some optional checks were not successful. They do not block the merge. 7 not successful, 50 successful. See the run.

Check Status
❌ CI: Optional E2E Tests / E2E node-eve (latest) Test (optional) Failing after 58s Details
❌ CI: Optional E2E Tests / E2E cloudflare-pi-durable (latest) Test (optional) Failing after 30s Details
❌ CI: Optional E2E Tests / E2E nextjs-16-cacheComponents (cloudflare) Test (optional) Failing after 10m Details
❌ CI: Optional E2E Tests / E2E node-eve Test (optional) Failing after 2m Details
❌ CI: Optional E2E Tests / E2E node-eve (orchestrion) Test (optional) Failing after 2m Details
❌ CI: Optional E2E Tests / E2E react-send-to-sentry Test (optional) Failing after 5m Details
❌ CI: Optional E2E Tests / E2E node-flue (latest) Test (optional) Failing after 29s Details
Successful checks
Check Status
✅ CI: Optional E2E Tests / E2E cloudflare-mastra Test (optional) Successful in 44s Details
✅ CI: Optional E2E Tests / E2E cloudflare-think Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E tanstackstart-react (latest) 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-15 (turbo) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E cloudflare-pi-durable Test (optional) Successful in 43s Details
✅ CI: Optional E2E Tests / E2E tanstackstart-react-sourcemaps Test (optional) Successful in 33s Details
✅ CI: Optional E2E Tests / E2E tanstackstart-react-cloudflare Test (optional) Successful in 51s Details
✅ CI: Optional E2E Tests / E2E vue-3 (no Options API) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E debug-id-sourcemaps Test (optional) Successful in 41s Details
✅ CI: Optional E2E Tests / E2E nextjs-16 (cloudflare, latest) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E supabase-nextjs Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E astro-7 Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E cloudflare-agent Test (optional) Successful in 47s Details
✅ CI: Optional E2E Tests / E2E cloudflare-flue-send-to-sentry Test (optional) Successful in 3m Details
✅ CI: Optional E2E Tests / E2E solidstart-2 Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nextjs-16 (deno) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E nextjs-orpc Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E deno (latest) 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 cloudflare-workers-send-to-sentry Test (optional) Successful in 4m Details
✅ CI: Optional E2E Tests / E2E gen-ai-libraries (latest) Test (optional) Successful in 46s Details
✅ CI: Optional E2E Tests / E2E nestjs-12 (latest) Test (optional) Successful in 53s Details
✅ CI: Optional E2E Tests / E2E nextjs-15 (latest) Test (optional) Successful in 4m Details
✅ CI: Optional E2E Tests / E2E cloudflare-think (ai v6) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E gen-ai-libraries (cloudflare) Test (optional) Successful in 55s Details
✅ CI: Optional E2E Tests / E2E nextjs-14 (latest) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E gen-ai-libraries Test (optional) Successful in 52s Details
✅ CI: Optional E2E Tests / E2E node-express-mcp-v1 Test (optional) Successful in 27s Details
✅ CI: Optional E2E Tests / E2E nextjs-16 (vinext) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-express-mcp-v2 Test (optional) Successful in 29s Details
✅ CI: Optional E2E Tests / E2E node-mastra Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nuxt-5-cloudflare Test (optional) Successful in 34s Details
✅ CI: Optional E2E Tests / E2E node-express-send-to-sentry Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E node-openai-decisions (latest) Test (optional) Successful in 32s Details
✅ CI: Optional E2E Tests / E2E node-pi-durable Test (optional) Successful in 43s Details
✅ CI: Optional E2E Tests / E2E nuxt-5 (tunnel-dev) Test (optional) Successful in 59s Details
✅ CI: Optional E2E Tests / E2E node-fastify-6 Test (optional) Successful in 36s Details
✅ CI: Optional E2E Tests / E2E node-fastify-6 (tracer provider) Test (optional) Successful in 37s Details
✅ CI: Optional E2E Tests / E2E node-express-send-to-sentry-static Test (optional) Successful in 3m Details
✅ CI: Optional E2E Tests / E2E nuxt-5-sourcemaps (static / nuxt generate) Test (optional) Successful in 38s Details
✅ CI: Optional E2E Tests / E2E react-router-7-framework-instrumentation Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E node-openai-decisions Test (optional) Successful in 29s Details
✅ CI: Optional E2E Tests / E2E node-pi-durable (latest) Test (optional) Successful in 43s Details
✅ CI: Optional E2E Tests / E2E nuxt-5 Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E node-mastra (latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-flue Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nuxt-5-sourcemaps (client source maps kept) Test (optional) Successful in 38s Details
✅ CI: Optional E2E Tests / E2E nextjs-16 (vinext, bun) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E nuxt-5-sourcemaps Test (optional) Successful in 39s Details

@logaretm
logaretm force-pushed the awad/runtime-tunnel-cloudflare branch from 29b761b to 0fa5a24 Compare November 2, 2026 21:29
@logaretm
logaretm force-pushed the awad/runtime-tunnel-cloudflare branch 2 times, most recently from 79c5b03 to ee6cc70 Compare November 3, 2026 04:10
@logaretm
logaretm force-pushed the awad/runtime-tunnel-cloudflare branch from ee6cc70 to dcc387e Compare November 3, 2026 04:21
@logaretm
logaretm force-pushed the awad/runtime-tunnel-cloudflare branch from dcc387e to 735789f Compare November 3, 2026 04:28
@logaretm
logaretm force-pushed the awad/runtime-tunnel-cloudflare branch 3 times, most recently from dc67ef5 to 02913e0 Compare November 3, 2026 04:50
@logaretm
logaretm marked this pull request as ready for review November 3, 2026 04:56
@logaretm
logaretm requested review from a team as code owners November 3, 2026 04:56
@logaretm
logaretm requested review from isaacs, mydea, nicohrubec and s1gr1d and removed request for a team November 3, 2026 04:56

@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.

Stale Bugbot comment from a previous run.

@logaretm
logaretm force-pushed the awad/runtime-tunnel-cloudflare branch 2 times, most recently from d0f5ad8 to 0ebb300 Compare November 4, 2026 17:25
@logaretm
logaretm force-pushed the awad/runtime-tunnel-cloudflare branch from 0ebb300 to 36182d9 Compare November 5, 2026 16:17

@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.

Stale Bugbot comment from a previous run.

Comment thread packages/astro/src/integration/index.ts Resolved
@logaretm
logaretm force-pushed the awad/runtime-tunnel-cloudflare branch from 36182d9 to 72c67bf Compare November 5, 2026 20:23
@logaretm
logaretm force-pushed the awad/runtime-tunnel-cloudflare branch 2 times, most recently from 0b90045 to 4272ef6 Compare November 6, 2026 01:56
@logaretm
logaretm force-pushed the awad/runtime-tunnel-cloudflare branch from 4272ef6 to a6ea10f Compare November 6, 2026 02:01

@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.

Stale Bugbot comment from a previous run.

plugins:
command !== 'dev'
? [sentryCloudflareNodeWarningPlugin(), sentryCloudflareVitePlugin()]
: [sentryCloudflareNodeWarningPlugin()],

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pages wrap drops tunnel client

High Severity

Production Pages builds now wrap the worker with withSentry(() => undefined), which inits a Cloudflare client that does not include serveTunnelIntegration. handleServedTunnelRequest and Astro middleware both read that client via getClient(), so managed tunnel requests are no longer answered. Pages previously relied on middleware and the server-init client, which this wrap replaces.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit a6ea10f. Configure here.

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.

Ah, yeah, this is valid, missed in my review. The Pages withSentry wrap replaces the user's client, so the tunnel stops answering (and events likely stop too).

The failure on Pages:

  1. The wrap is withSentry(() => undefined, ...), so getFinalOptions takes its options from Wrangler env only. On every request, wrapRequestHandlerWithInit calls initBaseSdk with them. That builds a CloudflareClient with no serveTunnelIntegration, and usually no DSN.
  2. initBaseSdk caches the first client of the isolate (packages/cloudflare/src/baseSdk.ts line 90). On each later request it calls setCurrentClient(cached), and the wrapper calls isolationScope.setClient(client).
  3. On Pages, @sentry/astro's server entry is @sentry/node. The user's sentry.server.config runs Sentry.init once, when the middleware module loads, and that is where serveTunnelIntegration() lives. From then on, getClient() returns the Cloudflare client. This is true both in handleServedTunnelRequest inside the wrapper and in packages/astro/src/server/middleware.ts line 93. Neither finds a served tunnel, so the request goes to the app.

The first request of an isolate may still work, because the middleware's init can bind the Node client after the wrapper let the request through. A quick manual check could miss the bug.

The effect is probably wider than the tunnel. On those later requests, events captured in the middleware and the pages also go to the env-only client. With no SENTRY_DSN binding, that client sends nothing, so a Pages app could stop reporting after the first request of each isolate. I did not confirm this at runtime.

Workers uses the same wrap, but under a different contract. dev-packages/e2e-tests/test-applications/astro-5-cf-workers sets SENTRY_DSN in wrangler.jsonc, and its sentry.server.config.js is empty on purpose ("The Worker wrapper initializes Sentry from Wrangler bindings"). Pages apps configure the SDK in sentry.server.config. Moving them onto the Workers wrap without that contract breaks them.

Suggestion: revert the Pages wrap in this PR, and leave the Pages tunnel to the Astro middleware. If Pages has to get the wrap, do it in its own PR. That PR has to pass the user's options to the wrap (or reuse the client from sentry.server.config, not an env-only one), or it has to move Pages to the Workers contract with a migration note. Add an Astro Pages e2e app (or a variant of astro-5). It should check the tunnel answer and an error event with the right request data on the second and later requests of an isolate, not only the first, and one server span per request.

@logaretm logaretm Nov 6, 2026 •

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.

So all forms of middlewares are getting cleaned up in the next PR, I don't want us to have both runtime-level interception and then app-level interception, so relying on the middleware isn't ideal.

I tried to verify this but looks like we have a blocker, the current CF pages sentry.server.config loads the client bundle not the server's. So the tunnel integration and logic doesn't even exist there. Will PR a fix and revisit this issue to see if we can verify it.

@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

One or more gzipped bundles increased by more than 500 bytes. If this increase is intentional, add the Accept Bundlesize Increase label to this PR to rerun and accept the check.

The Cloudflare request wrapper answers tunnel requests before the Worker's handler. Nuxt's Cloudflare plugin
passes the request with its body, and Astro wraps Pages builds with `withSentry` like Workers builds.
@logaretm
logaretm force-pushed the awad/runtime-tunnel-cloudflare branch from a6ea10f to e611657 Compare November 6, 2026 03:42

@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.

This change is small and fits the stack. 👍

I'd probably revert the Nuxt v2 body copy unless there is a demonstrated gap in the h3-layer tunnel.

…unnel requests

Every POST body went into the request the wrapper reads, so the SDK attached app request bodies to events.
…apper

Nitro v3 sends internal `$fetch` calls through `fetch` too, so each one during server rendering ran the Cloudflare
wrapper again, with another `init`, isolation scope and `http.server` span. Requests without the Worker's context
now go straight to the app. Adds a `nuxt-5-cloudflare` e2e app.
@logaretm
logaretm requested a review from a team as a code owner November 6, 2026 16:16
@logaretm
logaretm requested review from msonnb and removed request for a team November 6, 2026 16:16

@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.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

There are 2 total unresolved issues (including 1 from previous review).

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 9c444ce. Configure here.

headers: event.headers,
// Nitro read the body before calling `localFetch`. Only the managed tunnel answers from this request, so
// only its requests get the body, and other requests' bodies don't end up on events.
body: isServedTunnelRequest({ method: event.method, url: pathname }) ? event.body : undefined,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Tunnel body skipped before SDK init

High Severity

isServedTunnelRequest runs before wrapRequestHandler creates the Cloudflare client, and it is called without a client, so it falls back to getClient(). On this Cloudflare path the SDK is not initialized yet, so the check is always false and the tunnel POST body is omitted. handleServedTunnelRequest then treats a request with no body as not a tunnel request and never answers it. Previously every non-GET body was copied, so the wrapper could still serve the tunnel after init.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 9c444ce. Configure here.

This branch has not been deployed

No deployments
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.

2 participants