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

add uber-trace-id for request header #110

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import io.opentracing.SpanContext;
import io.opentracing.Tracer;
import io.opentracing.propagation.Format;
import io.opentracing.propagation.TextMapAdapter;
import io.opentracing.tag.Tags;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.web.server.ServerWebExchange;
Expand All @@ -28,7 +29,10 @@
import reactor.core.publisher.MonoOperator;
import reactor.util.context.Context;

import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

/**
* Similar to {@code MonoWebFilterTrace} from spring-cloud-sleuth-core.
Expand Down Expand Up @@ -72,7 +76,21 @@ public void subscribe(final CoreSubscriber<? super Void> subscriber) {

try (final Scope scope = tracer.scopeManager().activate(span, false)) {
exchange.getAttributes().put(TracingWebFilter.SERVER_SPAN_CONTEXT, span.context());
source.subscribe(new TracingSubscriber(subscriber, exchange, context, span, spanDecorators));
source.subscribe(new TracingSubscriber(subscriber, this.wrappleExchange(span), context, span, spanDecorators));
}
}

private ServerWebExchange wrappleExchange(Span span) {
Map<String, String> map = new HashMap();
this.tracer.inject(span.context(), Format.Builtin.HTTP_HEADERS, new TextMapAdapter(map));
ServerHttpRequest req = this.exchange.getRequest();
Iterator iterator = map.keySet().iterator();

while (iterator.hasNext()) {
aslongyouloveme marked this conversation as resolved.
Show resolved Hide resolved
String key = (String) iterator.next();
req.mutate().header(key, map.get(key));
}

return this.exchange.mutate().request(req).build();
}
}