Skip to content

Commit

Permalink
Allow reactor instrumentation to pick up spans in reactor context in …
Browse files Browse the repository at this point in the history
…addition to current tracing context
  • Loading branch information
lmolkova committed Sep 17, 2021
1 parent 59439cb commit a4d94df
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
* https://github.com/opentracing-contrib/java-reactor/blob/master/src/main/java/io/opentracing/contrib/reactor/TracedSubscriber.java
*/
public class TracingSubscriber<T> implements CoreSubscriber<T> {
public final static String EXPLICIT_SPAN_KEY = "otel-span-key";
private final io.opentelemetry.context.Context traceContext;
private final Subscriber<? super T> subscriber;
private final Context context;
Expand All @@ -45,7 +46,13 @@ public TracingSubscriber(
io.opentelemetry.context.Context contextToPropagate) {
this.subscriber = subscriber;
this.context = ctx;
this.traceContext = contextToPropagate;

var span = (Span)this.context.getOrDefault(EXPLICIT_SPAN_KEY, null);
if (span != null) {
this.traceContext = contextToPropagate.with(span);
} else {
this.traceContext = contextToPropagate;
}
}

@Override
Expand Down

0 comments on commit a4d94df

Please sign in to comment.