-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix(tracing): Baggage parsing fails when input is not of type string #5276
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
add handling for string array and warning in case it is something else
size-limit report 📦
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change looks great!
For my understanding: What this change means for the future is, that if any requests are incoming, that contain multiple baggage
headers, our SDK will take care of combining them into one singular outgoing header. Correct?
I thought about this for a bit, because at first it seemed a bit invasive, however, we need to do this for sentry tracing to work + we're actually being a good citizen because we're cleaning up after other vendors. Also we're adhering to spec so it should totally be fine if others adhere to the spec too.
const baggageEntries = (isString(inputBaggageValue) ? inputBaggageValue : inputBaggageValue.join(',')) | ||
.split(',') | ||
.map(entry => entry.trim()) | ||
.filter(entry => entry !== ''); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find this somehow very satisfying. :)
Yes and no. I tried to reproduce having incoming requests with multiple baggage headers and what I've found out was that Express apparently automatically combines them into one header (which is what the standard permits) . (Only reproduced this with Express, might of course be different for other frameworks in which case the parsing function should take care of the multiple headers as well). The one case where I could reproduce having an array of baggage headers instead of a string was when I simulated having another party add a baggage header with an array of elements to an outgoing request before we add our baggage header to that request. In this case our EDIT: I'll add this paragraph to the PR description for future readers |
Awesome thanks for clarifying! |
Btw, can we remove this type cast here now?
|
Good point. Would like to do that but after trying, TS still screams at me because a header item could be of types |
Ah right. Hmm, if I were to make a decision I would do the following (kinda a lot of work though):
I get it though that this would kinda explode the scope of this PR. I guess for now, casting to If you think what I'm suggesting above makes sense we can do this in a follow-up PR. |
I think it's a good idea and I had a similar thought in mind (although just not wrapping it with a type which is for sure nicer). I don't even think that it's out of the scope for this PR because in this very PR I changed the types already to accept and handle string arrays, so why not add the number in as well. |
gets rid of dangerous (and now unnecessary) type cast
This PR attempts to fix a bug reported in #5250 where the input parameter for
parseBaggageString
was not a string and hence thestring.split
function call would throw an error. This PR now checks for the type of the input and makes the functionAdditionally, the parser now ignores empty or blank baggage entries (e.g.
foo=bar, ,,alice=bob
).This is far from a proper, complete bugfix because we're missing an actual reproduction of the exact error but we got similar errors when experimenting with a Node/Express test app that would yield an array of baggage items rather than a string. However, it has the potential to fix it, or at least keep an error from emerging. Additionally, it makes the parser a little more robust.
Added some tests to describe/test how the parser now handles different input values.