Skip to content

feat(bun): Capture Bun.serve request bodies with maxRequestBodySize - #24233

Open
JosephDoUrden wants to merge 1 commit into
getsentry:developfrom
JosephDoUrden:fix/bun-request-body-capture
Open

feat(bun): Capture Bun.serve request bodies with maxRequestBodySize#24233
JosephDoUrden wants to merge 1 commit into
getsentry:developfrom
JosephDoUrden:fix/bun-request-body-capture

Conversation

@JosephDoUrden

Copy link
Copy Markdown
Contributor
  • If you've added code that should be tested, please add tests.
  • Ensure your code lints and the test suite passes (yarn lint) & (yarn test).
  • Link an issue if there is one related to your pull request. If no issue is linked, one will be auto-generated and linked.

Ports the Deno body capture from #22912 to Bun.serve. Same maxRequestBodySize option, same default (medium when httpBodies includes incomingRequest, otherwise none), GET skipped, body read before continueTrace so it lands on the request data. As on Deno an explicit maxRequestBodySize wins over httpBodies in both directions.

One side effect: normalizedRequest now comes from winterCGRequestToRequestData, so query_string loses the leading ? and is undefined instead of "" when there is no query. That matches what Deno, Cloudflare and Node already send, and the url.query span attribute Bun was already stripping.

The body read is awaited before the handler runs and core caps it at 2s, so a client that opens an upload and stalls holds the handler up to 2s even if the handler never reads the body. Same as Deno and Cloudflare, just new for Bun.

The isolation scope callback had to go async for the body read, so the wrapper returns a promise now. Bun.serve accepts either, and every non HEAD/OPTIONS path was already returning one via startSpan.

Tests: 10 new in bunserver.test.ts, 60/60 green for the package, plus a request-bodies suite in bun-integration-tests, 14/14 green.

Closes #23884

AI disclosure: AI assistance (Claude) was used for research and to draft the tests. The implementation was written and reviewed by the author.

Bun.serve handlers never captured request bodies, so dataCollection.httpBodies
and maxRequestBodySize did nothing there. Use the same WinterCG helpers as
Deno: winterCGRequestToRequestData for normalizedRequest and
captureBodyFromWinterCGRequest for the body. bunServerIntegration gets a
maxRequestBodySize option, an explicit value wins over httpBodies, GET is
skipped.

Swapping the hand-built normalizedRequest changes one field: query_string
loses the leading "?" (it was URL.search, the helper strips it like Deno,
Cloudflare and Node do). Headers are unchanged, both versions lower-case the
keys and neither filters at the source, requestDataIntegration does that
downstream against dataCollection.httpHeaders.request. The handler wrapper
is now async so it always returns a promise, which Bun.serve accepts.
@JosephDoUrden
JosephDoUrden requested a review from a team as a code owner September 9, 2026 10:03
@JosephDoUrden
JosephDoUrden requested review from JPeer264 and mydea and removed request for a team September 9, 2026 10:03
@JPeer264

Copy link
Copy Markdown
Member

bugbot run

@JPeer264

Copy link
Copy Markdown
Member

Thanks a lot for your contributions. I'll let bugbot run over it and once this one is done I'll take a closer look at the PR.

@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 e5d499d. Configure here.

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.

bun: Bun.serve does not capture request bodies

2 participants