From 32cacb629e593a6fbf66d21dcbc6b19efdc4fc12 Mon Sep 17 00:00:00 2001 From: Marcin Grzejszczak Date: Wed, 25 Jul 2018 11:04:23 +0200 Subject: [PATCH] Polished docs, fixed the build --- .../src/main/asciidoc/spring-cloud-sleuth.adoc | 4 ++++ .../async/AsyncAutoConfiguration.java | 2 +- .../async/ExecutorBeanPostProcessor.java | 14 +++++++------- ...perties.java => SleuthAsyncProperties.java} | 9 +++++++-- .../async/ExecutorBeanPostProcessorTests.java | 18 ++++++++---------- spring-cloud-sleuth-dependencies/pom.xml | 2 +- 6 files changed, 28 insertions(+), 21 deletions(-) rename spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/async/{AsyncProperties.java => SleuthAsyncProperties.java} (87%) diff --git a/docs/src/main/asciidoc/spring-cloud-sleuth.adoc b/docs/src/main/asciidoc/spring-cloud-sleuth.adoc index 6f2eab8fd..9273a41b8 100644 --- a/docs/src/main/asciidoc/spring-cloud-sleuth.adoc +++ b/docs/src/main/asciidoc/spring-cloud-sleuth.adoc @@ -1207,6 +1207,10 @@ include::../../../../spring-cloud-sleuth-core/src/test/java/org/springframework/ IMPORTANT: Sleuth does not work with `parallelStream()` out of the box. If you want to have the tracing information propagated through the stream, you have to use the approach with `supplyAsync(...)`, as shown earlier. +If there are beans that implement the `Executor` interface that you would like +to exclude from span creation, you can use the `spring.sleuth.async.ignored-beans` +property where you can provide a list of bean names. + ===== Customization of Executors Sometimes, you need to set up a custom instance of the `AsyncExecutor`. diff --git a/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/async/AsyncAutoConfiguration.java b/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/async/AsyncAutoConfiguration.java index 32c6ceadd..9c0580992 100644 --- a/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/async/AsyncAutoConfiguration.java +++ b/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/async/AsyncAutoConfiguration.java @@ -29,6 +29,6 @@ import org.springframework.scheduling.annotation.AsyncConfigurer; */ @Configuration -@EnableConfigurationProperties(AsyncProperties.class) +@EnableConfigurationProperties(SleuthAsyncProperties.class) public class AsyncAutoConfiguration { } diff --git a/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/async/ExecutorBeanPostProcessor.java b/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/async/ExecutorBeanPostProcessor.java index 8bc2ea255..a064e0cbc 100644 --- a/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/async/ExecutorBeanPostProcessor.java +++ b/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/async/ExecutorBeanPostProcessor.java @@ -47,7 +47,7 @@ class ExecutorBeanPostProcessor implements BeanPostProcessor { ExecutorBeanPostProcessor.class); private final BeanFactory beanFactory; - private AsyncProperties asyncProperties; + private SleuthAsyncProperties sleuthAsyncProperties; ExecutorBeanPostProcessor(BeanFactory beanFactory) { this.beanFactory = beanFactory; @@ -93,8 +93,8 @@ class ExecutorBeanPostProcessor implements BeanPostProcessor { } boolean isProxyNeeded(String beanName) { - AsyncProperties asyncProperties = asyncConfigurationProperties(); - return !asyncProperties.getIgnoredBeans().contains(beanName); + SleuthAsyncProperties sleuthAsyncProperties = asyncConfigurationProperties(); + return !sleuthAsyncProperties.getIgnoredBeans().contains(beanName); } Object createThreadPoolTaskExecutorProxy(Object bean, boolean cglibProxy, @@ -119,11 +119,11 @@ class ExecutorBeanPostProcessor implements BeanPostProcessor { return factory.getObject(); } - private AsyncProperties asyncConfigurationProperties() { - if (this.asyncProperties == null) { - this.asyncProperties = this.beanFactory.getBean(AsyncProperties.class); + private SleuthAsyncProperties asyncConfigurationProperties() { + if (this.sleuthAsyncProperties == null) { + this.sleuthAsyncProperties = this.beanFactory.getBean(SleuthAsyncProperties.class); } - return this.asyncProperties; + return this.sleuthAsyncProperties; } } diff --git a/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/async/AsyncProperties.java b/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/async/SleuthAsyncProperties.java similarity index 87% rename from spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/async/AsyncProperties.java rename to spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/async/SleuthAsyncProperties.java index 4c10e72c2..f4c06ff2c 100644 --- a/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/async/AsyncProperties.java +++ b/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/async/SleuthAsyncProperties.java @@ -29,13 +29,18 @@ import org.springframework.boot.context.properties.ConfigurationProperties; */ @ConfigurationProperties(prefix = "spring.sleuth.async") -public class AsyncProperties { - +public class SleuthAsyncProperties { + + /** + * List of {@link java.util.concurrent.Executor} bean names that should + * be ignored and not wrapped in a trace representation + */ private List ignoredBeans = Collections.emptyList(); public List getIgnoredBeans() { return this.ignoredBeans; } + public void setIgnoredBeans(List ignoredBeans) { this.ignoredBeans = ignoredBeans; } diff --git a/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/async/ExecutorBeanPostProcessorTests.java b/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/async/ExecutorBeanPostProcessorTests.java index 25991617a..3cfd18442 100644 --- a/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/async/ExecutorBeanPostProcessorTests.java +++ b/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/async/ExecutorBeanPostProcessorTests.java @@ -16,6 +16,7 @@ package org.springframework.cloud.sleuth.instrument.async; +import java.util.Collections; import java.util.concurrent.Executor; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; @@ -31,9 +32,6 @@ import org.springframework.beans.factory.BeanFactory; import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; import org.springframework.util.ClassUtils; -import com.google.common.collect.ImmutableList; - -import static org.junit.Assert.*; import static org.assertj.core.api.BDDAssertions.then; import static org.assertj.core.api.BDDAssertions.thenThrownBy; @@ -44,12 +42,12 @@ import static org.assertj.core.api.BDDAssertions.thenThrownBy; public class ExecutorBeanPostProcessorTests { @Mock BeanFactory beanFactory; - private AsyncProperties asyncProperties; + private SleuthAsyncProperties sleuthAsyncProperties; @Before public void setup() { - this.asyncProperties = new AsyncProperties(); - Mockito.when(beanFactory.getBean(AsyncProperties.class)).thenReturn(this.asyncProperties); + this.sleuthAsyncProperties = new SleuthAsyncProperties(); + Mockito.when(beanFactory.getBean(SleuthAsyncProperties.class)).thenReturn(this.sleuthAsyncProperties); } @Test @@ -124,23 +122,23 @@ public class ExecutorBeanPostProcessorTests { @Test public void proxy_is_not_needed() throws Exception { - this.asyncProperties.setIgnoredBeans(ImmutableList.of("fooExecutor")); + this.sleuthAsyncProperties.setIgnoredBeans(Collections.singletonList("fooExecutor")); boolean isProxyNeeded = new ExecutorBeanPostProcessor(this.beanFactory).isProxyNeeded("fooExecutor"); - assertFalse(isProxyNeeded); + then(isProxyNeeded).isFalse(); } @Test public void proxy_is_needed() throws Exception { boolean isProxyNeeded = new ExecutorBeanPostProcessor(this.beanFactory).isProxyNeeded("fooExecutor"); - assertTrue(isProxyNeeded); + then(isProxyNeeded).isTrue(); } @Test public void should_not_create_proxy() throws Exception { - this.asyncProperties.setIgnoredBeans(ImmutableList.of("fooExecutor")); + this.sleuthAsyncProperties.setIgnoredBeans(Collections.singletonList("fooExecutor")); Object o = new ExecutorBeanPostProcessor(this.beanFactory) .postProcessAfterInitialization(new ThreadPoolTaskExecutor(), "fooExecutor"); diff --git a/spring-cloud-sleuth-dependencies/pom.xml b/spring-cloud-sleuth-dependencies/pom.xml index 0085d1686..877d76291 100644 --- a/spring-cloud-sleuth-dependencies/pom.xml +++ b/spring-cloud-sleuth-dependencies/pom.xml @@ -25,7 +25,7 @@ spring-cloud-sleuth-dependencies - 2.0.1.BUILD-SNAPSHOT + 2.1.0.BUILD-SNAPSHOT pom spring-cloud-sleuth-dependencies Spring Cloud Sleuth Dependencies