Skip to content

feat(bun): Add client address, port and protocol to Bun.serve spans - #24523

Open
Shubham-Padkonde wants to merge 1 commit into
getsentry:developfrom
Shubham-Padkonde:bun-client-address
Open

Shubham-Padkonde wants to merge 1 commit into
getsentry:developfrom
Shubham-Padkonde:bun-client-address

Conversation

@Shubham-Padkonde

Copy link
Copy Markdown

Closes #23886

Bun.serve spans now set client.address, client.port and network.protocol.name, matching Deno.serve (wrap-deno-request-handler.ts).

  • Bun passes the Server as the second argument to both fetch and route handlers. wrapRequestHandler reads it from args[1] and calls server.requestIP(request), so the server doesn't have to be threaded through the proxies.
  • As in Deno, the first x-forwarded-for entry wins over the socket address for client.address, and both attributes are gated on dataCollection.userInfo.
  • network.protocol.name is always http.
  • requestIP is 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:

  • defaults on a fetch handler;
  • route handlers;
  • x-forwarded-for precedence;
  • userInfo: false.

Results, run locally with Bun 1.4.2:

  • bun test test/integrations/bunserver.test.ts: 31 pass. With the develop version of bunserver.ts, the 4 new tests fail.

  • bun test in packages/bun: 66 pass, 0 fail.

  • oxlint --type-aware and oxfmt --check are clean on both files, and tsc -p tsconfig.types.json --noEmit is 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

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
Shubham-Padkonde requested a review from a team as a code owner September 19, 2026 10:44
@Shubham-Padkonde
Shubham-Padkonde requested review from andreiborza and isaacs and removed request for a team September 19, 2026 10:44
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 spans lack client address and protocol attributes

1 participant