Reduces scope copies when desired context is already current (#1558)
This commit is contained in:
@@ -54,7 +54,9 @@ final class ScopePassingSpanSubscriber<T> implements SpanSubscription<T>, Scanna
|
||||
this.subscriber = subscriber;
|
||||
this.currentTraceContext = currentTraceContext;
|
||||
this.parent = parent;
|
||||
this.context = parent != null ? ctx.put(TraceContext.class, parent) : ctx;
|
||||
this.context = parent != null
|
||||
&& !parent.equals(ctx.getOrDefault(TraceContext.class, null))
|
||||
? ctx.put(TraceContext.class, parent) : ctx;
|
||||
if (log.isTraceEnabled()) {
|
||||
log.trace("Parent span [" + parent + "], context [" + this.context + "]");
|
||||
}
|
||||
|
||||
@@ -138,6 +138,18 @@ public class ScopePassingSpanSubscriberTests {
|
||||
then((String) subscriber.currentContext().get("foo")).isEqualTo("bar");
|
||||
}
|
||||
|
||||
/**
|
||||
* This ensures when the desired context is in the reactor context we don't copy it.
|
||||
*/
|
||||
@Test
|
||||
public void should_not_redundantly_copy_context() {
|
||||
Context initial = Context.of(TraceContext.class, context);
|
||||
ScopePassingSpanSubscriber<?> subscriber = new ScopePassingSpanSubscriber<>(null,
|
||||
initial, this.currentTraceContext, context);
|
||||
|
||||
then(initial).isSameAs(subscriber.currentContext());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_set_empty_context_when_context_is_null() {
|
||||
ScopePassingSpanSubscriber<?> subscriber = new ScopePassingSpanSubscriber<>(null,
|
||||
|
||||
Reference in New Issue
Block a user