Polished docs, fixed the build
This commit is contained in:
@@ -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`.
|
||||
|
||||
@@ -29,6 +29,6 @@ import org.springframework.scheduling.annotation.AsyncConfigurer;
|
||||
*/
|
||||
|
||||
@Configuration
|
||||
@EnableConfigurationProperties(AsyncProperties.class)
|
||||
@EnableConfigurationProperties(SleuthAsyncProperties.class)
|
||||
public class AsyncAutoConfiguration {
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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<String> ignoredBeans = Collections.emptyList();
|
||||
|
||||
public List<String> getIgnoredBeans() {
|
||||
return this.ignoredBeans;
|
||||
}
|
||||
|
||||
public void setIgnoredBeans(List<String> ignoredBeans) {
|
||||
this.ignoredBeans = ignoredBeans;
|
||||
}
|
||||
@@ -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");
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
<relativePath/>
|
||||
</parent>
|
||||
<artifactId>spring-cloud-sleuth-dependencies</artifactId>
|
||||
<version>2.0.1.BUILD-SNAPSHOT</version>
|
||||
<version>2.1.0.BUILD-SNAPSHOT</version>
|
||||
<packaging>pom</packaging>
|
||||
<name>spring-cloud-sleuth-dependencies</name>
|
||||
<description>Spring Cloud Sleuth Dependencies</description>
|
||||
|
||||
Reference in New Issue
Block a user