Added hystrix to skip pattern of scheduled and messaging channel name

fixes gh-986
This commit is contained in:
Marcin Grzejszczak
2018-05-22 18:57:36 +02:00
parent 70ff3afc7b
commit 2190cccb8c
5 changed files with 33 additions and 14 deletions

View File

@@ -1161,10 +1161,8 @@ If you annotate your method with `@Scheduled`, we automatically create a new spa
* The span is tagged with the method's class name and method name.
If you want to skip span creation for some `@Scheduled` annotated classes, you can set the `spring.sleuth.scheduled.skipPattern` with a regular expression that matches the fully qualified name of the `@Scheduled` annotated class.
TIP: If you use `spring-cloud-sleuth-stream` and `spring-cloud-netflix-hystrix-stream` together, a span is created for each Hystrix metrics and sent to Zipkin.
This behavior may be annoying.
You can prevent it by setting `spring.sleuth.scheduled.skipPattern=org.springframework.cloud.netflix.hystrix.stream.HystrixStreamTask`.
If you use `spring-cloud-sleuth-stream` and `spring-cloud-netflix-hystrix-stream` together, a span is created for each Hystrix metrics and sent to Zipkin.
This behavior may be annoying. That's why, by default, `spring.sleuth.scheduled.skipPattern=org.springframework.cloud.netflix.hystrix.stream.HystrixStreamTask`.
==== Executor, ExecutorService, and ScheduledExecutorService
@@ -1202,7 +1200,7 @@ It creates spans for publish and subscribe events.
To disable Spring Integration instrumentation, set `spring.sleuth.integration.enabled` to `false`.
You can provide the `spring.sleuth.integration.patterns` pattern to explicitly provide the names of channels that you want to include for tracing.
By default, all channels are included.
By default, all channels but `hystrixStreamOutput` channel are included.
IMPORTANT: When using the `Executor` to build a Spring Integration `IntegrationFlow`, you must use the untraced version of the `Executor`.
Decorating the Spring Integration Executor Channel with `TraceableExecutorService` causes the spans to be improperly closed.

View File

@@ -46,8 +46,26 @@ public class SleuthMessagingProperties {
}
public static class Integration {
/**
* An array of patterns against which channel names will be matched.
* @see org.springframework.integration.config.GlobalChannelInterceptor#patterns().
* Defaults to any channel name not matching the Hystrix Stream channel name.
*/
private String[] patterns = new String[] { "!hystrixStreamOutput*", "*" };
/**
* Enable Spring Integration sleuth instrumentation
*/
private boolean enabled;
public String[] getPatterns() {
return this.patterns;
}
public void setPatterns(String[] patterns) {
this.patterns = patterns;
}
public boolean isEnabled() {
return this.enabled;
}

View File

@@ -25,6 +25,7 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties
import org.springframework.cloud.sleuth.autoconfig.TraceAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.integration.channel.interceptor.GlobalChannelInterceptorWrapper;
import org.springframework.integration.config.GlobalChannelInterceptor;
/**
@@ -47,8 +48,16 @@ import org.springframework.integration.config.GlobalChannelInterceptor;
public class TraceSpringIntegrationAutoConfiguration {
@Bean
@GlobalChannelInterceptor(patterns = "${spring.sleuth.integration.patterns:*}")
public TracingChannelInterceptor traceChannelInterceptor(Tracing tracing) {
public GlobalChannelInterceptorWrapper tracingGlobalChannelInterceptorWrapper(
TracingChannelInterceptor interceptor,
SleuthMessagingProperties properties) {
GlobalChannelInterceptorWrapper wrapper = new GlobalChannelInterceptorWrapper(interceptor);
wrapper.setPatterns(properties.getIntegration().getPatterns());
return wrapper;
}
@Bean
TracingChannelInterceptor traceChannelInterceptor(Tracing tracing) {
return new TracingChannelInterceptor(tracing);
}

View File

@@ -35,7 +35,7 @@ public class SleuthSchedulingProperties {
/**
* Pattern for the fully qualified name of a class that should be skipped.
*/
private String skipPattern = "";
private String skipPattern = "org.springframework.cloud.netflix.hystrix.stream.HystrixStreamTask";
public boolean isEnabled() {
return this.enabled;

View File

@@ -1,10 +1,4 @@
{"properties": [
{
"name": "spring.sleuth.integration.patterns",
"type": "java.lang.String[]",
"description": "An array of simple patterns against which channel names will be matched. Default is * (all channels). See org.springframework.util.PatternMatchUtils.simpleMatch(String, String).",
"defaultValue": "*"
},
{
"name": "spring.sleuth.integration.enabled",
"type": "java.lang.Boolean",