Skip to content

feat(bun): keep server spans open until streaming responses finish - #25025

Open
minwookshin wants to merge 1 commit into
getsentry:developfrom
minwookshin:feat/bun-stream-response-spans
Open

minwookshin wants to merge 1 commit into
getsentry:developfrom
minwookshin:feat/bun-stream-response-spans

Conversation

@minwookshin

Copy link
Copy Markdown

Bun server spans now remain open until a streaming response completes, errors, or is cancelled. This shares the existing Cloudflare/Deno content-type classifier and preserves backpressure without buffering the response; ordinary responses still finish immediately.

The Bun regression and integration tests pass, including a real server case that fails before this change. Build, lint, formatting, and 41 of 42 package test tasks pass; Deno's existing concurrent-request context test fails both here and after rebuilding the unmodified base sources.

Fixes #23883.

Co-Authored-By: GPT-6 <codex@openai.com>
@github-actions github-actions Bot added the external PR from an external contributor label Oct 3, 2026
@minwookshin
minwookshin marked this pull request as ready for review October 5, 2026 02:25
@minwookshin
minwookshin requested a review from a team as a code owner October 5, 2026 02:25
@minwookshin
minwookshin requested review from andreiborza and mydea and removed request for a team October 5, 2026 02:25
headers: response.headers,
});
// pipeTo settles on completion, source errors, and downstream cancellation.
void response.body.pipeTo(writable).then(endSpan, endSpan);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Bug: Errors in streaming responses are silently discarded instead of being captured by Sentry, causing failed requests to be reported as successful.
Severity: HIGH

Suggested Fix

The rejection handler for the pipeTo promise should be modified to correctly handle the error. It should set the span status to an error state (e.g., 'internal_error') and capture the exception with Sentry before ending the span. This will ensure that failures during streaming are properly tracked.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: packages/bun/src/integrations/bunserver.ts#L332

Potential issue: The error handling for streaming responses is incorrect. The code at
`packages/bun/src/integrations/bunserver.ts:332` uses `void
response.body.pipeTo(writable).then(endSpan, endSpan);`. When the stream encounters an
error (e.g., client disconnection, network failure), the promise returned by `pipeTo`
rejects. The rejection handler, `endSpan`, is called, but the error itself is discarded.
This means the Sentry span is not updated to reflect the error status, and the exception
is never captured. Consequently, failed streaming requests are silently reported as
successful, which can mask underlying issues in production.

Also affects:

  • packages/deno/src/utils/streaming.ts:1~8

Did we get this right? 👍 / 👎 to inform future reviews.

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

external PR from an external contributor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bun: Bun.serve does not support streaming responses

1 participant