Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

rafis
Copy link

@rafis rafis commented Jan 23, 2023

Closes #340

@rafis rafis changed the title Do not overwrite client if incoming request has "uber-trace-id" header Do not overwrite client span if incoming request has "uber-trace-id" header Jan 23, 2023
@rafis rafis changed the title Do not overwrite client span if incoming request has "uber-trace-id" header Do not remove client span if incoming request has "uber-trace-id" header Jan 23, 2023
@lucacome lucacome requested a review from Copilot March 15, 2025 19:52
Copy link

@Copilot Copilot AI left a 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));
Copy link
Preview

Copilot AI Mar 15, 2025

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.

Suggested change
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.

Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

uber-trace-id from incoming request overwrites client span in spring cloud gateway tracing
1 participant