-
Notifications
You must be signed in to change notification settings - Fork 144
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
Do not remove client span if incoming request has "uber-trace-id" header #341
base: master
Are you sure you want to change the base?
Conversation
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.
Pull Request Overview
This PR ensures that the client span is preserved when an incoming request contains the "uber-trace-id" header by modifying how headers are merged.
- Replace addAll with a loop that adds headers only if absent using the first value in each header.
- Change header insertion in the builder to use putIfAbsent, preventing overwriting of existing headers.
Comments suppressed due to low confidence (1)
instrument-starters/opentracing-spring-cloud-gateway-starter/src/main/java/io/opentracing/contrib/spring/cloud/gateway/TraceRequestHttpHeadersFilter.java:91
- Using putIfAbsent here prevents overwriting of existing headers, but may also bypass merging where multiple values are expected. Confirm that this logic is consistent with how header values should be combined during propagation.
headersWithInput.putIfAbsent(key, value);
@@ -66,7 +66,9 @@ public HttpHeaders filter(HttpHeaders input, ServerWebExchange exchange) { | |||
} catch (Exception ignore) { | |||
log.error("TraceRequestHttpHeadersFilter error", ignore); | |||
} | |||
headersWithInput.addAll(input); | |||
for (Map.Entry<String, List<String>> entry : input.entrySet()) { | |||
headersWithInput.addIfAbsent(entry.getKey(), entry.getValue().get(0)); |
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.
Only the first value of each header is preserved here, which may drop additional header values that might be required for some cases. Consider a solution that combines all values if preserving the full header list is necessary.
headersWithInput.addIfAbsent(entry.getKey(), entry.getValue().get(0)); | |
headersWithInput.addAll(entry.getKey(), entry.getValue()); |
Copilot is powered by AI, so mistakes are possible. Review output carefully before use.
Closes #340