diff --git a/benchmarks/src/test/java/org/springframework/cloud/sleuth/benchmarks/jmh/Pair.java b/benchmarks/src/test/java/org/springframework/cloud/sleuth/benchmarks/jmh/Pair.java index 8167ede4a..8799e4ba8 100644 --- a/benchmarks/src/test/java/org/springframework/cloud/sleuth/benchmarks/jmh/Pair.java +++ b/benchmarks/src/test/java/org/springframework/cloud/sleuth/benchmarks/jmh/Pair.java @@ -34,7 +34,7 @@ public class Pair { } public static Pair noHook() { - return new Pair("spring.sleuth.reactor.decorate-hooks", "false"); + return new Pair("spring.sleuth.reactor.decorate-queues", "false"); } public static Pair noSleuth() { diff --git a/docs/src/main/asciidoc/spring-cloud-sleuth.adoc b/docs/src/main/asciidoc/spring-cloud-sleuth.adoc index f207bf515..c018d932d 100644 --- a/docs/src/main/asciidoc/spring-cloud-sleuth.adoc +++ b/docs/src/main/asciidoc/spring-cloud-sleuth.adoc @@ -1528,7 +1528,7 @@ To turn off this feature, set the `spring.sleuth.quartz.enabled` property to `fa ==== From Spring Cloud Sleuth 2.2.8 (inclusive) -With the new Reactor https://github.com/reactor/reactor-core/pull/2566[queue wrapping mechanism] (Reactor 3.3.14) we're instrumenting the way threads are switched by Reactor. You should observe significant improvement in performance. In order to disable this feature you have to set the `spring.sleuth.reactor.decorate-hooks` option to `false`. You'll fall back to the previous instrumentation mode mechanism. +With the new Reactor https://github.com/reactor/reactor-core/pull/2566[queue wrapping mechanism] (Reactor 3.3.14) we're instrumenting the way threads are switched by Reactor. You should observe significant improvement in performance. In order to disable this feature you have to set the `spring.sleuth.reactor.decorate-queues` option to `false`. You'll fall back to the previous instrumentation mode mechanism. ==== To Spring Cloud Sleuth 2.2.8 (exclusive) diff --git a/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/reactor/SleuthReactorProperties.java b/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/reactor/SleuthReactorProperties.java index c402afda3..435d86df8 100644 --- a/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/reactor/SleuthReactorProperties.java +++ b/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/reactor/SleuthReactorProperties.java @@ -34,11 +34,11 @@ public class SleuthReactorProperties { private boolean enabled = true; /** - * When true uses the new decorate hooks feature from Project Reactor. Should allow + * When true uses the new decorate queues feature from Project Reactor. Should allow * the feature set of {@link SleuthReactorProperties#decorateOnEach} with the least * impact on the performance. */ - private boolean decorateHooks = true; + private boolean decorateQueues = true; /** * When true decorates on each operator, will be less performing, but logging will @@ -46,8 +46,8 @@ public class SleuthReactorProperties { * operator, will be more performing, but logging might not always contain the tracing * entries. * - * If {@link SleuthReactorProperties#decorateHooks} is used, this decoration mode will - * NOT be used. + * If {@link SleuthReactorProperties#decorateQueues} is used, this decoration mode + * will NOT be used. */ private boolean decorateOnEach = true; @@ -59,12 +59,12 @@ public class SleuthReactorProperties { this.enabled = enabled; } - public boolean isDecorateHooks() { - return this.decorateHooks; + public boolean isDecorateQueues() { + return this.decorateQueues; } - public void setDecorateHooks(boolean decorateHooks) { - this.decorateHooks = decorateHooks; + public void setDecorateQueues(boolean decorateQueues) { + this.decorateQueues = decorateQueues; } public boolean isDecorateOnEach() { diff --git a/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/reactor/TraceReactorAutoConfiguration.java b/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/reactor/TraceReactorAutoConfiguration.java index 9fba5d5d2..52fee9b6a 100644 --- a/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/reactor/TraceReactorAutoConfiguration.java +++ b/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/reactor/TraceReactorAutoConfiguration.java @@ -100,7 +100,7 @@ public class TraceReactorAutoConfiguration { SleuthReactorProperties reactorProperties = this.springContext .getBean(SleuthReactorProperties.class); if (TraceReactorAutoConfiguration.TraceReactorConfiguration.IS_QUEUE_WRAPPER_ON_THE_CLASSPATH - && reactorProperties.isDecorateHooks()) { + && reactorProperties.isDecorateQueues()) { if (log.isTraceEnabled()) { log.trace("Resetting queue wrapper instrumentation"); } @@ -175,7 +175,7 @@ class HooksRefresher implements ApplicationListener Hooks.resetOnEachOperator(SLEUTH_TRACE_REACTOR_KEY); Hooks.resetOnLastOperator(SLEUTH_TRACE_REACTOR_KEY); Hooks.removeQueueWrapper(SLEUTH_TRACE_REACTOR_KEY); - if (this.reactorProperties.isDecorateHooks() + if (this.reactorProperties.isDecorateQueues() && TraceReactorAutoConfiguration.TraceReactorConfiguration.IS_QUEUE_WRAPPER_ON_THE_CLASSPATH) { if (log.isTraceEnabled()) { log.trace("Adding queue wrapper instrumentation"); @@ -227,16 +227,16 @@ class HookRegisteringBeanDefinitionRegistryPostProcessor static void setupHooks(ConfigurableApplicationContext springContext) { ConfigurableEnvironment environment = springContext.getEnvironment(); - Boolean decorateHooks = environment - .getProperty("spring.sleuth.reactor.decorate-hooks", Boolean.class); - if (wrapperNotOnClasspathButPropertyHasValue(decorateHooks)) { + Boolean decorateQueues = environment + .getProperty("spring.sleuth.reactor.decorate-queues", Boolean.class); + if (wrapperNotOnClasspathButPropertyHasValue(decorateQueues)) { log.warn( "You have explicitly set the decorate hooks option but you're using an old version of Reactor. Please upgrade to the latest Boot version (at least 2.3.9.RELEASE). Will fall back to the previous reactor instrumentation mode"); } else { - decorateHooks = decorateHooks != null ? decorateHooks : Boolean.TRUE; + decorateQueues = decorateQueues != null ? decorateQueues : Boolean.TRUE; } - if (wrapperOnClasspathHooksPropertyTurnedOn(decorateHooks)) { + if (wrapperOnClasspathHooksPropertyTurnedOn(decorateQueues)) { if (log.isTraceEnabled()) { log.trace("Adding queue wrapper instrumentation"); } @@ -263,12 +263,14 @@ class HookRegisteringBeanDefinitionRegistryPostProcessor decorateScheduler(springContext); } - private static boolean wrapperOnClasspathHooksPropertyTurnedOn(Boolean decorateHooks) { + private static boolean wrapperOnClasspathHooksPropertyTurnedOn( + Boolean decorateHooks) { return Boolean.TRUE.equals(decorateHooks) && TraceReactorAutoConfiguration.TraceReactorConfiguration.IS_QUEUE_WRAPPER_ON_THE_CLASSPATH; } - private static boolean wrapperNotOnClasspathButPropertyHasValue(Boolean decorateHooks) { + private static boolean wrapperNotOnClasspathButPropertyHasValue( + Boolean decorateHooks) { return !TraceReactorAutoConfiguration.TraceReactorConfiguration.IS_QUEUE_WRAPPER_ON_THE_CLASSPATH && decorateHooks != null; } @@ -286,7 +288,6 @@ class HookRegisteringBeanDefinitionRegistryPostProcessor Hooks.resetOnEachOperator(SLEUTH_TRACE_REACTOR_KEY); Hooks.resetOnLastOperator(SLEUTH_TRACE_REACTOR_KEY); Hooks.removeQueueWrapper(SLEUTH_REACTOR_EXECUTOR_SERVICE_KEY); - Schedulers.resetOnScheduleHook(SLEUTH_REACTOR_EXECUTOR_SERVICE_KEY); Schedulers.resetOnScheduleHook( TraceReactorAutoConfiguration.SLEUTH_REACTOR_EXECUTOR_SERVICE_KEY); } diff --git a/tests/spring-cloud-sleuth-instrumentation-reactor-tests/src/test/java/org/springframework/cloud/sleuth/instrument/reactor/sample/FlatMapTests.java b/tests/spring-cloud-sleuth-instrumentation-reactor-tests/src/test/java/org/springframework/cloud/sleuth/instrument/reactor/sample/FlatMapTests.java index 37d820260..1dae54a11 100644 --- a/tests/spring-cloud-sleuth-instrumentation-reactor-tests/src/test/java/org/springframework/cloud/sleuth/instrument/reactor/sample/FlatMapTests.java +++ b/tests/spring-cloud-sleuth-instrumentation-reactor-tests/src/test/java/org/springframework/cloud/sleuth/instrument/reactor/sample/FlatMapTests.java @@ -101,7 +101,7 @@ public class FlatMapTests { FlatMapTests.TestConfiguration.class, Issue866Configuration.class) .web(WebApplicationType.REACTIVE) .properties("server.port=0", "spring.jmx.enabled=false", - "spring.sleuth.reactor.decorate-hooks=false", + "spring.sleuth.reactor.decorate-queues=false", "spring.sleuth.reactor.decorate-on-each=true", "spring.application.name=TraceWebFluxOnEachTests", "security.basic.enabled=false", @@ -117,7 +117,7 @@ public class FlatMapTests { FlatMapTests.TestConfiguration.class, Issue866Configuration.class) .web(WebApplicationType.REACTIVE) .properties("server.port=0", "spring.jmx.enabled=false", - "spring.sleuth.reactor.decorate-hooks=false", + "spring.sleuth.reactor.decorate-queues=false", "spring.sleuth.reactor.decorate-on-each=false", "spring.application.name=TraceWebFluxOnLastTests", "security.basic.enabled=false", @@ -126,14 +126,14 @@ public class FlatMapTests { assertReactorTracing(context); try { - System.setProperty("spring.sleuth.reactor.decorate-hooks", "false"); + System.setProperty("spring.sleuth.reactor.decorate-queues", "false"); System.setProperty("spring.sleuth.reactor.decorate-on-each", "false"); // trigger context refreshed context.getBean(ContextRefresher.class).refresh(); assertReactorTracing(context); } finally { - System.clearProperty("spring.sleuth.reactor.decorate-hooks"); + System.clearProperty("spring.sleuth.reactor.decorate-queues"); System.clearProperty("spring.sleuth.reactor.decorate-on-each"); } }