Skip to content
Open
Changes from all commits
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();
if (map.isEmpty()) {
return this.exchange;
} else {
for (String key : map.keySet()) {
req.mutate().header(key, map.get(key));
}
}
return this.exchange.mutate().request(req).build();
}
}