Skip to content

feat(cloudflare): Add isStreamingResponse option and detect streamed RSC responses - #24932

Merged
JPeer264 merged 6 commits into
developfrom
jp/cloudflare-streaming-response-detection
Oct 19, 2026
Merged

JPeer264 merged 6 commits into
developfrom
jp/cloudflare-streaming-response-detection

Conversation

@JPeer264

@JPeer264 JPeer264 commented Oct 1, 2026 •

Copy link
Copy Markdown
Member

closes #22876
closes JS-3236

Description

This adds an isStreamingResponse option, so users can keep the http.server span open until a streamed response has been sent, for example for streamed SSR pages. Spans created while the body streams then stay inside the request.

  • text/x-component (RSC) responses without a Content-Length header now count as streamed by default. The classifier is shared, so this also applies to Bun and Deno.
  • Precompressed bodies with encodeBody: 'manual' are no longer compressed a second time.
  • Workers with a compatibility date before 2022-11-30 send the span again. They ignore the TransformStream transformer, so the SDK ends the span at handler return there.
export default defineCloudflareOptions(env => ({
  dsn: env.SENTRY_DSN, 
  isStreamingResponse: response =>
    response.headers.get('content-type')?.startsWith('text/html') ? true : undefined,
}));

Detection decisions

HTML is not streamed by default, because a buffered new Response(html) has no Content-Length header either and would also go through the TransformStream. The alternative is to treat HTML without a Content-Length as streamed, which fixes streamed SSR without configuration.

@github-actions

github-actions Bot commented Oct 1, 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 29.88 kB - -
@sentry/browser - with treeshaking flags 28.02 kB - -
@sentry/browser - with treeshaking flags tracing without tracing 27.92 kB - -
@sentry/browser (incl. Tracing) 52.07 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 52.07 kB - -
@sentry/browser (incl. Tracing, Profiling) 55.02 kB - -
@sentry/browser (incl. Tracing, Replay) 91.82 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 80.68 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 96.55 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 109.49 kB - -
@sentry/browser (incl. Feedback) 47.4 kB - -
@sentry/browser (incl. sendFeedback) 34.94 kB - -
@sentry/browser (incl. FeedbackAsync) 40.05 kB - -
@sentry/browser (incl. Metrics) 30.9 kB - -
@sentry/browser (incl. Logs) 31.18 kB - -
@sentry/browser (incl. Metrics & Logs) 31.81 kB - -
@sentry/react 31.7 kB - -
@sentry/react (incl. Tracing) 54.39 kB - -
@sentry/vue 38.04 kB - -
@sentry/vue (incl. Tracing) 55.01 kB - -
@sentry/svelte 29.9 kB - -
@sentry/remix (Remix 3 client bundle) 57.08 kB - -
CDN Bundle 31.64 kB - -
CDN Bundle (incl. Tracing) 52.58 kB - -
CDN Bundle (incl. Logs, Metrics) 33.84 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 54.52 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 74.77 kB - -
CDN Bundle (incl. Tracing, Replay) 90.25 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 92.18 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 96.4 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 98.34 kB - -
CDN Bundle - uncompressed 93.18 kB - -
CDN Bundle (incl. Tracing) - uncompressed 156.03 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 99.72 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 161.99 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 229.76 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 276.2 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 282.14 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 289.9 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 295.84 kB - -
@sentry/nextjs (client) 56.8 kB - -
@sentry/sveltekit (client) 52.45 kB - -
@sentry/core/server 41.14 kB +0.04% +13 B 🔺
@sentry/core/browser 13.81 kB - -
@sentry/node 153.1 kB +0.02% +17 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 84.04 kB - -
@sentry/node - without tracing 94.88 kB +0.01% +7 B 🔺
@sentry/node - without channel injection 131.15 kB +0.01% +5 B 🔺
@sentry/aws-serverless 103.04 kB +0.01% +4 B 🔺
@sentry/cloudflare (withSentry) - minified 210.7 kB +0.05% +104 B 🔺
@sentry/cloudflare (withSentry) 522.8 kB +0.06% +274 B 🔺
@sentry/nextjs/cloudflare (withSentry) - minified 228.38 kB +0.05% +106 B 🔺

View base workflow run

@JPeer264
JPeer264 added this pull request to stack #24934 October 1, 2026 11:32
@JPeer264

JPeer264 commented Oct 1, 2026

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 4356442. Configure here.

@JPeer264
JPeer264 marked this pull request as ready for review October 1, 2026 13:44
@JPeer264
JPeer264 requested a review from a team as a code owner October 1, 2026 13:44
@JPeer264
JPeer264 requested review from isaacs and mydea and removed request for a team October 1, 2026 13:44
@JPeer264 JPeer264 self-assigned this Oct 1, 2026
@JPeer264
JPeer264 requested review from andreiborza and removed request for mydea October 1, 2026 13:44

@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 coercion of all buffered responses to streaming feels a bit risky without an escape hatch to work around it, since workerd responses don't have a corollary to Deno's info.completed.

I think this is a good compromise, but would recommend adding the explicit hook option for users that find they need to disable this in some cases.

Comment thread packages/cloudflare/src/utils/streaming.ts Outdated
Comment thread packages/cloudflare/src/wrapRequestHandlerWithInit.ts Outdated
JPeer264 and others added 4 commits October 8, 2026 13:38
… RSC responses

Streamed SSR (`text/html`) and RSC (`text/x-component`) responses were
classified as non-streaming, so the root span ended when the handler
returned and spans that ended while the body streamed were lost. Both
content types are now treated as streaming when the response has no
Content-Length, the same rule that `text/plain` already uses.

The SDK now creates the streamed response with the original response as
the init. This keeps `encodeBody: 'manual'`, so workerd no longer
compresses an already compressed body a second time.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…TML and RSC responses

Without the `transformstream_enable_standard_constructor` compatibility
flag (compatibility dates before 2022-11-30, which Hydrogen's mini-oxygen
uses), workerd ignores the transformer, so `flush` and `cancel` never ran
and the span was never sent. Such Workers now end the span at handler
return, as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@JPeer264
JPeer264 force-pushed the jp/cloudflare-streaming-response-detection branch from 4356442 to ee216da Compare October 8, 2026 11:51
@linear-code

linear-code Bot commented Oct 8, 2026

Copy link
Copy Markdown

JS-3236

@JPeer264
JPeer264 requested a review from isaacs October 9, 2026 07:10

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

Some nits and suggestions that can definitely be follow-ups.

Also: text/x-script (React Router 7 / Remix single fetch turbo-stream) is not detected, and Bun and Deno get the RSC change but no hook. The hook covers Cloudflare users for now, which is good, but incomplete.

We should track a follow-up to add the same option to Bun and Deno, so the shared heuristic has the same per-runtime override everywhere.

Comment thread packages/cloudflare/src/client.ts Outdated
Comment thread packages/cloudflare/src/wrapRequestHandlerWithInit.ts Outdated
Comment thread packages/cloudflare/src/client.ts Outdated
Comment thread packages/cloudflare/src/wrapRequestHandlerWithInit.ts Outdated
@JPeer264 JPeer264 changed the title fix(cloudflare): Keep the http.server span open for streamed HTML and RSC responses feat(cloudflare): Add isStreamingResponse option and detect streamed RSC responses Oct 19, 2026
@JPeer264

Copy link
Copy Markdown
Member Author

Added a follow up in #25537

@JPeer264
JPeer264 merged commit d6c8d82 into develop Oct 19, 2026
735 of 737 checks passed
@JPeer264
JPeer264 deleted the jp/cloudflare-streaming-response-detection branch October 19, 2026 17:01
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.

Provide a mechanism to override classifyResponseStreaming behaviour

2 participants