Merge branch '2.1.x'
This commit is contained in:
@@ -16,6 +16,8 @@
|
||||
|
||||
package org.springframework.cloud.sleuth.instrument.reactor;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.BooleanSupplier;
|
||||
import java.util.function.Function;
|
||||
|
||||
@@ -84,8 +86,7 @@ public abstract class ReactorSleuth {
|
||||
+ "]");
|
||||
}
|
||||
|
||||
return scopePassingSpanSubscription(beanFactory.getBean(Tracing.class),
|
||||
sub);
|
||||
return scopePassingSpanSubscription(beanFactory, sub);
|
||||
}
|
||||
if (log.isTraceEnabled()) {
|
||||
log.trace("Spring Context [" + beanFactory
|
||||
@@ -104,9 +105,12 @@ public abstract class ReactorSleuth {
|
||||
scannable.name());
|
||||
}
|
||||
|
||||
static <T> CoreSubscriber<? super T> scopePassingSpanSubscription(Tracing tracing,
|
||||
CoreSubscriber<? super T> sub) {
|
||||
private static Map<BeanFactory, Tracing> CACHE = new ConcurrentHashMap<>();
|
||||
|
||||
static <T> CoreSubscriber<? super T> scopePassingSpanSubscription(
|
||||
BeanFactory beanFactory, CoreSubscriber<? super T> sub) {
|
||||
Tracing tracing = CACHE.computeIfAbsent(beanFactory,
|
||||
beanFactory1 -> beanFactory1.getBean(Tracing.class));
|
||||
Context context = sub.currentContext();
|
||||
|
||||
Span root = context.hasKey(Span.class) ? context.get(Span.class)
|
||||
|
||||
@@ -21,11 +21,14 @@ import brave.Tracer;
|
||||
import brave.Tracing;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.BDDMockito;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import reactor.core.CoreSubscriber;
|
||||
import reactor.core.publisher.BaseSubscriber;
|
||||
import reactor.util.context.Context;
|
||||
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
|
||||
/**
|
||||
@@ -58,7 +61,7 @@ public class ScopePassingSpanSubscriberTests {
|
||||
try (Tracer.SpanInScope ws = this.tracing.tracer()
|
||||
.withSpanInScope(span.start())) {
|
||||
CoreSubscriber<?> subscriber = ReactorSleuth.scopePassingSpanSubscription(
|
||||
this.tracing, new BaseSubscriber<Object>() {
|
||||
beanFactory(), new BaseSubscriber<Object>() {
|
||||
});
|
||||
|
||||
then(subscriber.currentContext().get(Span.class)).isEqualTo(span);
|
||||
@@ -66,4 +69,10 @@ public class ScopePassingSpanSubscriberTests {
|
||||
|
||||
}
|
||||
|
||||
private BeanFactory beanFactory() {
|
||||
BeanFactory beanFactory = BDDMockito.mock(BeanFactory.class);
|
||||
BDDMockito.given(beanFactory.getBean(Tracing.class)).willReturn(this.tracing);
|
||||
return beanFactory;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user