feat(bun): Set http response header attributes instead of response context headers#19821
Merged
feat(bun): Set http response header attributes instead of response context headers#19821
Conversation
Contributor
size-limit report 📦
|
Contributor
node-overhead report 🧳Note: This is a synthetic benchmark with a minimal express app and does not necessarily reflect the real-world performance impact in an application.
|
Lms24
commented
Mar 16, 2026
Comment on lines
+232
to
238
| if (headerValue == null) { | ||
| return; | ||
| } | ||
|
|
||
| const normalizedKey = `http.${lifecycle}.header.${normalizeAttributeKey(headerKey)}${cookieKey ? `.${normalizeAttributeKey(cookieKey)}` : ''}`; | ||
| spanAttributes[normalizedKey] = headerValue; | ||
| } |
Member
Author
There was a problem hiding this comment.
These are just minimal optimizations for performance/bundle size but I don't think they fully paid off. Main reasoning: If we do nothing on headerValue === undefined we can also early return and save the little time it takes to compute the header key. Happy to revert if reviewers prefer the old version.
s1gr1d
approved these changes
Mar 17, 2026
Lms24
commented
Mar 17, 2026
Lms24
added a commit
that referenced
this pull request
Mar 17, 2026
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.
This PR addresses the issue reported in #19790 where our Bun serve instrumentation blindly attached all HTTP response headers to request contexts. This was problematic as explained in the issue since sensitive headers could have been sent.
This PR ensures we no longer do this, while retaining safe response header:
httpHeadersToSpanAttributeshelper from core to also generatehttp.responseheaders if an optionallifecycleparameter is added to the callcontexts.response.headers: We never do this. In Node, we only set the response status on this context.http.serverspan. By leveraginghttpHeadersToSpanAttributeswe now have the same sensitive data mechanisms in place as with request headers which we already send this way. Meaning, a bunch of authorization headers are filtered always, and cookie/set-cookie headers are filtered depending onsendDefaultPii.Note: This can be considered a subtle behaviour break but given the incorrectness of always setting response headers unconditionally before, I think this is justified. Contexts are not indexed, hence alerts can't be built on top of them and neither saved discover or explore queries. I'm also not aware of Relay promoting
respnose.header.*values to tags, so we should be safe here.Closes #19790