feat(bun): Add client address, port and protocol to Bun.serve spans - #24523
Open
Shubham-Padkonde wants to merge 1 commit into
Open
Shubham-Padkonde wants to merge 1 commit into
Shubham-Padkonde wants to merge 1 commit into
Conversation
Bun.serve spans lacked the `client.address`, `client.port` and `network.protocol.name` attributes that Deno.serve spans set. Read the peer from `server.requestIP(request)` (Bun passes the server as the second handler argument), let the first `x-forwarded-for` entry win for the address, and gate both on `dataCollection.userInfo` like Deno does. Closes getsentry#23886 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Shubham-Padkonde
requested review from
andreiborza and
isaacs
and removed request for
a team
September 19, 2026 10:44
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #23886
Bun.servespans now setclient.address,client.portandnetwork.protocol.name, matchingDeno.serve(wrap-deno-request-handler.ts).Serveras the second argument to bothfetchand route handlers.wrapRequestHandlerreads it fromargs[1]and callsserver.requestIP(request), so the server doesn't have to be threaded through the proxies.x-forwarded-forentry wins over the socket address forclient.address, and both attributes are gated ondataCollection.userInfo.network.protocol.nameis alwayshttp.requestIPis guarded by a type check and a try/catch, so a missing or throwing implementation (for example on a request that didn't come from the server's socket) just leaves the attributes unset.Tests
There are 4 new tests in
packages/bun/test/integrations/bunserver.test.ts, covering:fetchhandler;x-forwarded-forprecedence;userInfo: false.Results, run locally with Bun 1.4.2:
bun test test/integrations/bunserver.test.ts: 31 pass. With thedevelopversion ofbunserver.ts, the 4 new tests fail.bun testinpackages/bun: 66 pass, 0 fail.oxlint --type-awareandoxfmt --checkare clean on both files, andtsc -p tsconfig.types.json --noEmitis clean.If you've added code that should be tested, please add tests.
Ensure your code lints and the test suite passes.
Link an issue if there is one related to your pull request.
This change was written with help from an AI coding assistant (Claude Code). I reviewed and tested it as described above.
🤖 Generated with Claude Code