GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — ref(cloudflare): Use the shared request handler wrapper by isaacs · Pull Request #25588 · getsentry/sentry-javascript

Conversation

@isaacs

@isaacs isaacs commented Oct 20, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Moves Cloudflare's wrapRequestHandler onto wrapServerRequestHandler, which Deno.serve and Bun.serve use since the previous PRs. Cloudflare keeps only what is unique to it: client init, the cf and cloud resource contexts, the protocol from cf.httpProtocol, the isStreamingResponse option, captureErrors, and the flush through waitUntil, which skips the dispose for a 101 response. The helpers that only the old code used (captureIncomingRequestBody, shouldCreateIncomingRequestSpan, getIncomingRequestSpanHooks and addRequest) are gone.

wrapRequestHandler must run on workers without the nodejs_compat flag, such as Shopify Oxygen, and every @sentry/server-utils entry loads node:async_hooks. So the wrapper moves to a new entry, @sentry/server-utils/request-handler, with no Node.js imports. Deno and Bun import it from there too. Cloudflare's module graph test allows this one entry, and a new test in server-utils walks the entry's module graph and fails on any Node.js import.

The wrapper gets three optional fields: isStreamingResponse, onDone (called once when the request is done, with the response if there is one), and a mechanism that can be left out to not capture errors.

For streamed responses, the shared stream monitor replaces Cloudflare's TransformStream. Workers with a compatibility date before 2022-11-30 cannot construct a ReadableStream without the streams_enable_constructors flag, so the wrapper then ends at handler return, as the TransformStream fallback did. The monitor now locks the source body only in start(), so the original response stays usable in that case. The wrapper builds the new response from the original one, which keeps encodeBody: 'manual'.

Visible changes for Cloudflare:

  • Request spans set client.address from CF-Connecting-IP (or another forwarding header), as on the other runtimes. This follows dataCollection.userInfo, which is true by default.
  • Request spans get the response header attributes, and events get the response context.
  • An error from the source of a streamed response is captured (unless captureErrors is false), and the span gets an error status.
  • If the user removed httpServerIntegration, request bodies follow dataCollection.httpBodies. Before, the SDK attached no body.

The minified withSentry bundle grows by about 2.4 KB (212,385 to 214,853 bytes), under the 211 KiB limit. Most of it is the request session and client address code, which Cloudflare now shares.

Fixes #25577
Fixes JS-3975

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@linear-code

linear-code Bot commented Oct 20, 2026

Copy link
Copy Markdown

JS-3975

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@isaacs
isaacs added this pull request to stack #25589 October 20, 2026 22:30
cursor[bot]
cursor Bot reviewed Oct 20, 2026
View reviewed changes

@cursor cursor Bot left a comment •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

There was a problem hiding this comment.

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread packages/cloudflare/src/wrapRequestHandlerWithInit.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

@github-actions

github-actions Bot commented Oct 20, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

size-limit report 📦

Compared: f032e07 (PR test merge using develop at b63640b)

Against: b63640b (develop) · base run #64512

✅ Baseline matches: this diff contains only this PR's changes.

Path Size % Change Change
@sentry/browser 30.39 kB - -
@sentry/browser - with treeshaking flags 28.54 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.98 kB - -
@sentry/browser (incl. sendFeedback) 35.5 kB - -
@sentry/browser (incl. FeedbackAsync) 40.6 kB - -
@sentry/browser (incl. Metrics) 31.43 kB - -
@sentry/browser (incl. Logs) 31.72 kB - -
@sentry/browser (incl. Metrics & Logs) 32.44 kB - -
@sentry/react 32.28 kB - -
@sentry/react (incl. Tracing) 55.08 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.79 kB - -
CDN Bundle 32.18 kB - -
CDN Bundle (incl. Tracing) 53.23 kB - -
CDN Bundle (incl. Logs, Metrics) 34.46 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 55.17 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 75.87 kB - -
CDN Bundle (incl. Tracing, Replay) 91.45 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 93.38 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 97.55 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 99.55 kB - -
CDN Bundle - uncompressed 94.64 kB - -
CDN Bundle (incl. Tracing) - uncompressed 157.6 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 101.11 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 163.34 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 232.68 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 293 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 298.71 kB - -
@sentry/nextjs (client) 58.03 kB - -
@sentry/sveltekit (client) 53.23 kB - -
@sentry/core/server 44.24 kB - -
@sentry/core/browser 13.93 kB - -
@sentry/node 155.5 kB +0.02% +19 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 82.16 kB - -
@sentry/node - without tracing 96.79 kB +0.03% +20 B 🔺
@sentry/node - without channel injection 135.86 kB +0.02% +20 B 🔺
@sentry/aws-serverless 104.99 kB +0.03% +21 B 🔺
@sentry/cloudflare (withSentry) - minified 200.64 kB +1.37% +2.71 kB 🔺
@sentry/cloudflare (withSentry) 499 kB +1.43% +7.03 kB 🔺
@sentry/nextjs/cloudflare (withSentry) - minified 221.18 kB +1.24% +2.7 kB 🔺

View base workflow run

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@isaacs
isaacs force-pushed the isaacschlueter/js-3975-share-one-request-handler-wrapper-across-denoserve-bunserve-c branch from fc30522 to 5d3ee29 Compare October 21, 2026 01:06
@isaacs
isaacs marked this pull request as ready for review October 21, 2026 01:07
@isaacs
isaacs requested a review from a team as a code owner October 21, 2026 01:07
@isaacs
isaacs requested review from JPeer264 and andreiborza and removed request for a team October 21, 2026 01:07
@isaacs
isaacs force-pushed the isaacschlueter/js-3975-share-one-request-handler-wrapper-across-denoserve-bunserve-c branch from 5d3ee29 to 7a1874d Compare October 21, 2026 01:07
@isaacs
isaacs requested a review from a team as a code owner October 21, 2026 01:13
@isaacs
isaacs requested review from chargome and nicohrubec and removed request for a team October 21, 2026 01:13
@isaacs
isaacs force-pushed the isaacschlueter/js-3975-share-one-request-handler-wrapper-across-denoserve-bunserve-c branch from 7a1874d to 9e86e46 Compare October 21, 2026 01:13
@isaacs
isaacs force-pushed the isaacschlueter/js-3975-share-one-request-handler-wrapper-across-denoserve-bunserve-c branch 2 times, most recently from a650894 to 66b9312 Compare October 21, 2026 01:20
cursor[bot]
cursor Bot reviewed Oct 21, 2026
View reviewed changes

@cursor cursor Bot left a comment •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

There was a problem hiding this comment.

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread dev-packages/cloudflare-integration-tests/suites/public-api/startSpan/test.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

@isaacs isaacs mentioned this pull request Oct 21, 2026
Flaky test: maybeSetUpTunnelRouteRewriteRules times out on slow CI runners #25591
Closed
@isaacs
isaacs force-pushed the isaacschlueter/js-3975-share-one-request-handler-wrapper-across-denoserve-bunserve-c branch from a1a478b to f0da1bc Compare October 21, 2026 04:14
@isaacs isaacs mentioned this pull request Oct 21, 2026
fix: Use auto.http.http_server origin for all node:http server spans #25604
Merged
@isaacs
isaacs force-pushed the isaacschlueter/js-3975-share-one-request-handler-wrapper-across-denoserve-bunserve-c branch from f0da1bc to 128c6ee Compare October 21, 2026 17:15
cursor[bot]
cursor Bot reviewed Oct 21, 2026
View reviewed changes

@cursor cursor Bot left a comment •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

There was a problem hiding this comment.

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread ...dflare-integration-tests/suites/tracing/opentelemetry-tracer/subpath-request-handler/test.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

@isaacs
isaacs force-pushed the isaacschlueter/js-3975-share-one-request-handler-wrapper-across-denoserve-bunserve-c branch from 3c42ed4 to 0ec0e9c Compare October 26, 2026 19:35
Base automatically changed from isaacschlueter/js-3975-share-one-request-handler-wrapper-across-denoserve-bunserve-b to develop October 26, 2026 23:27
@isaacs
isaacs force-pushed the isaacschlueter/js-3975-share-one-request-handler-wrapper-across-denoserve-bunserve-c branch from 0ec0e9c to 06363f7 Compare October 26, 2026 23:27
mydea
mydea reviewed Oct 28, 2026
View reviewed changes
Comment thread packages/server-utils/src/index.request-handler.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

chargome
chargome reviewed Oct 28, 2026
View reviewed changes
Comment thread CHANGELOG.md Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread .size-limit.js Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread packages/cloudflare/src/integrations/httpServer.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

@isaacs
isaacs force-pushed the isaacschlueter/js-3975-share-one-request-handler-wrapper-across-denoserve-bunserve-c branch from 06363f7 to 2be491f Compare October 29, 2026 17:09
@isaacs
isaacs requested a review from a team as a code owner October 29, 2026 17:09
@isaacs
isaacs requested review from chargome, logaretm, msonnb and mydea and removed request for a team October 29, 2026 17:09
@isaacs
isaacs force-pushed the isaacschlueter/js-3975-share-one-request-handler-wrapper-across-denoserve-bunserve-c branch 2 times, most recently from 05dc8e3 to 881f9f5 Compare October 29, 2026 17:39
@logaretm logaretm mentioned this pull request Oct 29, 2026
feat: Answer managed tunnel requests in the runtimes instead of the framework hooks #25917
Closed
logaretm
logaretm reviewed Oct 30, 2026
View reviewed changes

@logaretm logaretm left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

LGTM, but a minor thing that got flagged when I was testing this for the tunnels work.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread packages/server-utils/src/utils/wrapServerRequestHandler.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

isaacs and others added 5 commits October 30, 2026 11:41
@isaacs @claude
ref(cloudflare): Use the shared request handler wrapper
3110b85
Moves Cloudflare's `wrapRequestHandler` onto `wrapServerRequestHandler`,
which `Deno.serve` and `Bun.serve` use since the previous PRs. Cloudflare
keeps only what is unique to it: client init, the `cf` and cloud
resource contexts, the protocol from `cf.httpProtocol`, the
`isStreamingResponse` option, `captureErrors`, and the flush through
`waitUntil`, which skips the dispose for a 101 response. The helpers
that only the old code used (`captureIncomingRequestBody`,
`shouldCreateIncomingRequestSpan`, `getIncomingRequestSpanHooks` and
`addRequest`) are gone.

`wrapRequestHandler` must run on workers without the `nodejs_compat`
flag, such as Shopify Oxygen, and every `@sentry/server-utils` entry
loads `node:async_hooks`. So the wrapper moves to a new entry,
`@sentry/server-utils/request-handler`, with no Node.js imports. Deno
and Bun import it from there too. Cloudflare's module graph test allows
this one entry, and a new test in server-utils walks the entry's module
graph and fails on any Node.js import.

The wrapper gets three optional fields: `isStreamingResponse`, `onDone`
(called once when the request is done, with the response if there is
one), and a `mechanism` that can be left out to not capture errors.

For streamed responses, the shared stream monitor replaces Cloudflare's
`TransformStream`. Workers with a compatibility date before 2022-11-30
cannot construct a `ReadableStream` without the
`streams_enable_constructors` flag, so the wrapper then ends at handler
return, as the `TransformStream` fallback did. The monitor now locks the
source body only in `start()`, so the original response stays usable in
that case. The wrapper builds the new response from the original one,
which keeps `encodeBody: 'manual'`.

Visible changes for Cloudflare:

- Request spans set `client.address` from `CF-Connecting-IP` (or
  another forwarding header), as on the other runtimes. This follows
  `dataCollection.userInfo`, which is `true` by default.
- Request spans get the response header attributes, and events get the
  `response` context.
- An error from the source of a streamed response is captured (unless
  `captureErrors` is `false`), and the span gets an error status.
- If the user removed `httpServerIntegration`, request bodies follow
  `dataCollection.httpBodies`. Before, the SDK attached no body.

The minified `withSentry` bundle grows by about 2.4 KB (212,385 to
214,853 bytes), under the 211 KiB limit. Most of it is the request
session and client address code, which Cloudflare now shares.

Fixes #25577
Fixes JS-3975

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@isaacs @claude
fix(cloudflare): Attach request data to the current scope without Asy…
37f8a37
…ncLocalStorage

Without `AsyncLocalStorage` (for example on Shopify Oxygen, or on
Workers without `nodejs_compat`), the SDK uses the stack fallback, and
`withInvocationIsolationScope` does not fork. The scope it passes to its
callback is a clone that is not the current isolation scope. The shared
request handler wrote the request data and body to that clone, so an
event captured in the handler, which reads the current scope, had no
request body. The `hydrogen-react-router-7` E2E test caught this.

The handler now gets the current isolation scope. With
`AsyncLocalStorage`, that is the same scope as before. Without it, the
request data goes where the body went before the move to the shared
handler, and events now also get the request URL and method.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@isaacs
fix(server-utils): correct comment in no-diagnostics-channel export b…
bad2f24
…arrel
@isaacs
fix(cloudflare): reword comment on getHttpServerRequestOptions
78bca2f
@isaacs @claude
fix(server-utils): Clear the previous request's body and response con…
7a0c28f
…text

Without `AsyncLocalStorage`, all requests use the default isolation
scope, which lives as long as the isolate. `setSDKProcessingMetadata`
merges into the existing `normalizedRequest`, so a request without a
body kept the body of an earlier request. The `response` context of
the earlier request also stayed set. For example, an error in a `GET`
after a `POST /login` got the login password as `request.data` and the
status code of the `POST` response.

The shared request handler now clears both at the start of each
request.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@isaacs
isaacs force-pushed the isaacschlueter/js-3975-share-one-request-handler-wrapper-across-denoserve-bunserve-c branch from 881f9f5 to 7a0c28f Compare October 30, 2026 18:42
@isaacs
isaacs requested a review from logaretm October 30, 2026 18:58
logaretm
logaretm approved these changes Oct 30, 2026
View reviewed changes

@logaretm logaretm left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Nice!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@isaacs
isaacs enabled stacked auto-merge (squash) October 30, 2026 19:02
@isaacs
isaacs merged commit c16633e into develop Oct 30, 2026
539 of 570 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@isaacs
isaacs deleted the isaacschlueter/js-3975-share-one-request-handler-wrapper-across-denoserve-bunserve-c branch October 30, 2026 19:06
@sentry-release-bot sentry-release-bot Bot mentioned this pull request Nov 5, 2026
publish: getsentry/[email protected] getsentry/publish#10234
Closed
51 tasks done
@github-actions github-actions Bot mentioned this pull request Nov 5, 2026
Share one  Request  handler wrapper across Deno.serve, Bun.serve and Cloudflare #25577
Closed
@JPeer264 JPeer264 mentioned this pull request Nov 17, 2026
Cloudflare Request and response attribute asymmetry against Deno #24042
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@cursor cursor[bot] cursor[bot] left review comments
@logaretm logaretm logaretm approved these changes
@JPeer264 JPeer264 Awaiting requested review from JPeer264 JPeer264 was automatically assigned from getsentry/team-javascript-sdks-server
@andreiborza andreiborza Awaiting requested review from andreiborza andreiborza was automatically assigned from getsentry/team-javascript-sdks-server
@nicohrubec nicohrubec Awaiting requested review from nicohrubec nicohrubec was automatically assigned from getsentry/team-javascript-sdks-framework
@msonnb msonnb Awaiting requested review from msonnb msonnb was automatically assigned from getsentry/team-javascript-sdks-browser
@mydea mydea Awaiting requested review from mydea
@chargome chargome Awaiting requested review from chargome

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Share one  Request  handler wrapper across Deno.serve, Bun.serve and Cloudflare

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@isaacs @mydea @logaretm @chargome
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.