Repository navigation
Conversation
Previously, the undici instrumentation added traceparent, tracestate, and baggage to each outgoing request with request.addHeader(), which validates each pair before appending it. Now an appended traceparent goes straight onto undici's flat array of header names and values. microtel makes that value, so the validation had nothing to catch. tracestate and baggage carry values from elsewhere and keep going through addHeader(), and so does any header when the array is not in that shape. Appending a header drops from about 77 ns to about 16. Signed-off-by: Bryan English <bryan@bryanenglish.com>
bengl
marked this pull request as ready for review
November 3, 2026 19:43
AbhiPrasad
approved these changes
Nov 4, 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.
The undici instrumentation adds
traceparentto every outgoing undici and fetch request, andtracestateandbaggagewhen the span has them. It added each one withrequest.addHeader(), which validates the pair before appending it to undici's flat array of header names and values.traceparentnow goes onto that array directly.Why only traceparent. microtel builds the
traceparentvalue from IDs and flags it generated or already validated, soaddHeader()has nothing to catch there, and every request carries one.tracestateandbaggagecarry values that came from elsewhere, so they keep going throughaddHeader(). A test checks which names reach it.Why it's safe. For a lowercase name that isn't one of undici's special headers, such as
hostorcontent-length,addHeader()validates the value and pushes the pair as given. undici's HTTP/1 writer and HTTP/2 header builder both read the array in pairs. When the headers aren't an even-length array, the append falls back toaddHeader(), so an undici that stores headers differently can't break requests.Performance. Per appended header, on Node 26.12.1, over 7 interleaved runs:
addHeader()That's about 60 ns per request, around 0.1% of a traced fetch, which is below this machine's noise in the fetch benchmark.
Tests.
addHeader()seestracestateandbaggagebut nottraceparent.traceparent, throughaddHeader().