-
Notifications
You must be signed in to change notification settings - Fork 834
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
Fix opentracing header name issue #5840
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -20,6 +20,7 @@ | |||||||
import java.util.Arrays; | ||||||||
import java.util.Collection; | ||||||||
import java.util.Collections; | ||||||||
import java.util.Locale; | ||||||||
import javax.annotation.Nullable; | ||||||||
import javax.annotation.concurrent.Immutable; | ||||||||
|
||||||||
|
@@ -108,14 +109,16 @@ public <C> Context extract(Context context, @Nullable C carrier, TextMapGetter<C | |||||||
if (carrier != null) { | ||||||||
BaggageBuilder baggageBuilder = Baggage.builder(); | ||||||||
for (String key : getter.keys(carrier)) { | ||||||||
if (!key.startsWith(PREFIX_BAGGAGE_HEADER)) { | ||||||||
String lowercaseKey = key.toLowerCase(Locale.ROOT); | ||||||||
if (!lowercaseKey.startsWith(PREFIX_BAGGAGE_HEADER)) { | ||||||||
continue; | ||||||||
} | ||||||||
String value = getter.get(carrier, key); | ||||||||
if (value == null) { | ||||||||
continue; | ||||||||
} | ||||||||
baggageBuilder.put(key.replace(OtTracePropagator.PREFIX_BAGGAGE_HEADER, ""), value); | ||||||||
String baggageKey = lowercaseKey.replace(OtTracePropagator.PREFIX_BAGGAGE_HEADER, ""); | ||||||||
baggageBuilder.put(baggageKey, value); | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Using substring preserves the case of the baggage key There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can not preserve the case of the baggage key anyway. They are carried in http headers and headers are case insensitive. The servlet implementations, and upstream services (sometimes) change it. I have seen several type of changes:
I think, since there is no guarantee of baggage name casing, we can at least keep it consistent and lowercase it everywhere (as tomcat does). Of course I have no strong objection with your changes and if you still prefer your changes I can apply them. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: I think it would be better to use substring on the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done! |
||||||||
} | ||||||||
Baggage baggage = baggageBuilder.build(); | ||||||||
if (!baggage.isEmpty()) { | ||||||||
|
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.
alternatively could use
to avoid converting the whole key
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.
If we decided to keep the case of header, I will also apply this change.