Refactored the way we decorate reactor scheduler
This commit is contained in:
@@ -16,9 +16,6 @@
|
||||
|
||||
package org.springframework.cloud.sleuth.instrument.reactor;
|
||||
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import javax.annotation.PreDestroy;
|
||||
|
||||
import brave.Tracing;
|
||||
@@ -58,6 +55,8 @@ import org.springframework.context.annotation.Configuration;
|
||||
@AutoConfigureAfter(TraceWebFluxAutoConfiguration.class)
|
||||
public class TraceReactorAutoConfiguration {
|
||||
|
||||
static final String SLEUTH_REACTOR_EXECUTOR_SERVICE_KEY = "sleuth";
|
||||
|
||||
@Configuration
|
||||
@ConditionalOnBean(Tracing.class)
|
||||
static class TraceReactorConfiguration {
|
||||
@@ -86,7 +85,8 @@ public class TraceReactorAutoConfiguration {
|
||||
log.trace("Cleaning up hooks");
|
||||
}
|
||||
Hooks.resetOnLastOperator(SLEUTH_TRACE_REACTOR_KEY);
|
||||
Schedulers.resetFactory();
|
||||
Schedulers
|
||||
.removeExecutorServiceDecorator(SLEUTH_REACTOR_EXECUTOR_SERVICE_KEY);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -118,17 +118,11 @@ class HookRegisteringBeanDefinitionRegistryPostProcessor
|
||||
Hooks.onLastOperator(
|
||||
TraceReactorAutoConfiguration.TraceReactorConfiguration.SLEUTH_TRACE_REACTOR_KEY,
|
||||
ReactorSleuth.scopePassingSpanOperator(this.context));
|
||||
Schedulers.setFactory(factoryInstance(beanFactory));
|
||||
}
|
||||
|
||||
private Schedulers.Factory factoryInstance(final BeanFactory beanFactory) {
|
||||
return new Schedulers.Factory() {
|
||||
@Override
|
||||
public ScheduledExecutorService decorateExecutorService(String schedulerType,
|
||||
Supplier<? extends ScheduledExecutorService> actual) {
|
||||
return new TraceableScheduledExecutorService(beanFactory, actual.get());
|
||||
}
|
||||
};
|
||||
Schedulers.setExecutorServiceDecorator(
|
||||
TraceReactorAutoConfiguration.SLEUTH_REACTOR_EXECUTOR_SERVICE_KEY,
|
||||
(scheduler,
|
||||
scheduledExecutorService) -> new TraceableScheduledExecutorService(
|
||||
beanFactory, scheduledExecutorService));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -127,8 +127,8 @@ public class TraceAsyncIntegrationTests {
|
||||
.getSpans();
|
||||
zipkin2.Span reportedAsyncSpan = spans.stream()
|
||||
.filter(span2 -> span2.name().equals("invoke-asynchronous-logic"))
|
||||
.findFirst()
|
||||
.orElseThrow(() -> new AssertionError("Should have a span with custom name"));
|
||||
.findFirst().orElseThrow(() -> new AssertionError(
|
||||
"Should have a span with custom name"));
|
||||
then(reportedAsyncSpan.traceId()).isEqualTo(span.context().traceIdString());
|
||||
then(reportedAsyncSpan.name()).isEqualTo("invoke-asynchronous-logic");
|
||||
then(reportedAsyncSpan.tags())
|
||||
@@ -146,8 +146,8 @@ public class TraceAsyncIntegrationTests {
|
||||
then(spans).hasSize(2);
|
||||
zipkin2.Span reportedAsyncSpan = spans.stream()
|
||||
.filter(span -> span.name().equals("invoke-asynchronous-logic"))
|
||||
.findFirst()
|
||||
.orElseThrow(() -> new AssertionError("Should have a span with custom name"));
|
||||
.findFirst().orElseThrow(() -> new AssertionError(
|
||||
"Should have a span with custom name"));
|
||||
then(reportedAsyncSpan.tags())
|
||||
.contains(new AbstractMap.SimpleEntry<>("class",
|
||||
"ClassPerformingAsyncLogic"))
|
||||
@@ -166,9 +166,9 @@ public class TraceAsyncIntegrationTests {
|
||||
.getSpans();
|
||||
then(spans).hasSize(2);
|
||||
zipkin2.Span reportedAsyncSpan = spans.stream()
|
||||
.filter(span2 -> span2.name().equals("foo"))
|
||||
.findFirst()
|
||||
.orElseThrow(() -> new AssertionError("Should have a span with custom name"));
|
||||
.filter(span2 -> span2.name().equals("foo")).findFirst()
|
||||
.orElseThrow(() -> new AssertionError(
|
||||
"Should have a span with custom name"));
|
||||
then(reportedAsyncSpan.traceId()).isEqualTo(span.context().traceIdString());
|
||||
then(reportedAsyncSpan.name()).isEqualTo("foo");
|
||||
then(reportedAsyncSpan.tags())
|
||||
@@ -184,9 +184,9 @@ public class TraceAsyncIntegrationTests {
|
||||
List<zipkin2.Span> spans = TraceAsyncIntegrationTests.this.reporter
|
||||
.getSpans();
|
||||
zipkin2.Span reportedAsyncSpan = spans.stream()
|
||||
.filter(span2 -> span2.name().equals("foo"))
|
||||
.findFirst()
|
||||
.orElseThrow(() -> new AssertionError("Should have a span with custom name"));
|
||||
.filter(span2 -> span2.name().equals("foo")).findFirst()
|
||||
.orElseThrow(() -> new AssertionError(
|
||||
"Should have a span with custom name"));
|
||||
then(reportedAsyncSpan.name()).isEqualTo("foo");
|
||||
then(reportedAsyncSpan.tags())
|
||||
.contains(new AbstractMap.SimpleEntry<>("class",
|
||||
|
||||
@@ -28,5 +28,6 @@
|
||||
<suppress files=".*TracingFeignClient.*" checks="LineLengthCheck"/>
|
||||
<suppress files=".*WebClientTests.*" checks="LineLengthCheck"/>
|
||||
<suppress files=".*SamplerAutoConfiguration.*" checks="HideUtilityClassConstructorCheck"/>
|
||||
<suppress files=".*TraceReactorAutoConfiguration.*" checks="HideUtilityClassConstructorCheck"/>
|
||||
<suppress files=".*grpc.stubs.*" checks=".*"/>
|
||||
</suppressions>
|
||||
|
||||
Reference in New Issue
Block a user