Merge branch '1.3.x' into 2.0.x

This commit is contained in:
Marcin Grzejszczak
2018-08-22 11:28:35 +02:00
5 changed files with 60 additions and 8 deletions

View File

@@ -1031,6 +1031,12 @@ You can configure which URIs you would like to skip by setting the `spring.sleut
If you have `ManagementServerProperties` on classpath, its value of `contextPath` gets appended to the provided skip pattern.
If you want to reuse the Sleuth's default skip patterns and just append your own, pass those patterns by using the `spring.sleuth.web.additionalSkipPattern`.
To change the order of tracing filter registration, please set the
`spring.sleuth.web.filter-order` property.
To disable the filter that logs uncaught exceptions you can disable the
`spring.sleuth.web.exception-throwing-filter-enabled` property.
==== HandlerInterceptor
Since we want the span names to be precise, we use a `TraceHandlerInterceptor` that either wraps an existing `HandlerInterceptor` or is added directly to the list of existing `HandlerInterceptors`.
@@ -1052,6 +1058,9 @@ You can configure which URIs you would like to skip by using the `spring.sleuth.
If you have `ManagementServerProperties` on the classpath, its value of `contextPath` gets appended to the provided skip pattern.
If you want to reuse Sleuth's default skip patterns and append your own, pass those patterns by using the `spring.sleuth.web.additionalSkipPattern`.
To change the order of tracing filter registration, please set the
`spring.sleuth.web.filter-order` property.
==== Dubbo RPC support
Via the integration with Brave, Spring Cloud Sleuth supports http://dubbo.io/[Dubbo].

View File

@@ -47,6 +47,17 @@ public class SleuthWebProperties {
*/
private String additionalSkipPattern;
/**
* Order in which the tracing filters should be registered.
* Defaults to {@link TraceHttpAutoConfiguration#TRACING_FILTER_ORDER}
*/
private int filterOrder = TraceHttpAutoConfiguration.TRACING_FILTER_ORDER;
/**
* Flag to toggle the presence of a filter that logs thrown exceptions
*/
private boolean exceptionThrowingFilterEnabled = true;
private Client client;
public boolean isEnabled() {
@@ -73,6 +84,27 @@ public class SleuthWebProperties {
this.additionalSkipPattern = additionalSkipPattern;
}
public static String getDefaultSkipPattern() {
return DEFAULT_SKIP_PATTERN;
}
public int getFilterOrder() {
return this.filterOrder;
}
public void setFilterOrder(int filterOrder) {
this.filterOrder = filterOrder;
}
public boolean isExceptionThrowingFilterEnabled() {
return this.exceptionThrowingFilterEnabled;
}
public void setExceptionThrowingFilterEnabled(
boolean exceptionThrowingFilterEnabled) {
this.exceptionThrowingFilterEnabled = exceptionThrowingFilterEnabled;
}
public Client getClient() {
return this.client;
}

View File

@@ -31,6 +31,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
/**
* {@link org.springframework.boot.autoconfigure.EnableAutoConfiguration Auto-configuration}
@@ -46,6 +47,8 @@ import org.springframework.context.annotation.Configuration;
@EnableConfigurationProperties({TraceKeys.class, SleuthHttpLegacyProperties.class})
public class TraceHttpAutoConfiguration {
static final int TRACING_FILTER_ORDER = Ordered.HIGHEST_PRECEDENCE + 5;
@Autowired HttpClientParser clientParser;
@Autowired HttpServerParser serverParser;
@Autowired @ClientSampler HttpSampler clientSampler;

View File

@@ -63,7 +63,7 @@ public final class TraceWebFilter implements WebFilter, Ordered {
* have the tracing context passed for you out of the box. That means that e.g. your
* logs will not get correlated.
*/
public static final int ORDER = Ordered.HIGHEST_PRECEDENCE + 5;
public static final int ORDER = TraceHttpAutoConfiguration.TRACING_FILTER_ORDER;
static final Propagation.Getter<HttpHeaders, String> GETTER =
new Propagation.Getter<HttpHeaders, String>() {
@@ -84,6 +84,7 @@ public final class TraceWebFilter implements WebFilter, Ordered {
Tracer tracer;
HttpServerHandler<ServerHttpRequest, ServerHttpResponse> handler;
TraceContext.Extractor<HttpHeaders> extractor;
SleuthWebProperties webProperties;
private final BeanFactory beanFactory;
TraceWebFilter(BeanFactory beanFactory) {
@@ -115,6 +116,13 @@ public final class TraceWebFilter implements WebFilter, Ordered {
return this.extractor;
}
SleuthWebProperties sleuthWebProperties() {
if (this.webProperties == null) {
this.webProperties = this.beanFactory.getBean(SleuthWebProperties.class);
}
return this.webProperties;
}
@Override public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
if (tracer().currentSpan() != null) {
// clear any previous trace
@@ -251,7 +259,7 @@ public final class TraceWebFilter implements WebFilter, Ordered {
}
@Override public int getOrder() {
return ORDER;
return sleuthWebProperties().getFilterOrder();
}
static final class DecoratedServerHttpResponse extends ServerHttpResponseDecorator {

View File

@@ -32,7 +32,6 @@ import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.core.Ordered;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import static javax.servlet.DispatcherType.ASYNC;
@@ -57,7 +56,7 @@ import static javax.servlet.DispatcherType.REQUEST;
@Import(SpanCustomizingAsyncHandlerInterceptor.class)
public class TraceWebServletAutoConfiguration {
public static final int TRACING_FILTER_ORDER = Ordered.HIGHEST_PRECEDENCE + 5;
public static final int TRACING_FILTER_ORDER = TraceHttpAutoConfiguration.TRACING_FILTER_ORDER;
/**
* Nested config that configures Web MVC if it's present (without adding a runtime
@@ -83,18 +82,19 @@ public class TraceWebServletAutoConfiguration {
@Bean
public FilterRegistrationBean traceWebFilter(
TracingFilter tracingFilter) {
TracingFilter tracingFilter, SleuthWebProperties webProperties) {
FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean(tracingFilter);
filterRegistrationBean.setDispatcherTypes(ASYNC, ERROR, FORWARD, INCLUDE, REQUEST);
filterRegistrationBean.setOrder(TraceWebServletAutoConfiguration.TRACING_FILTER_ORDER);
filterRegistrationBean.setOrder(webProperties.getFilterOrder());
return filterRegistrationBean;
}
@Bean
public FilterRegistrationBean exceptionThrowingFilter() {
@ConditionalOnProperty(value = "spring.sleuth.web.exceptionThrowingFilterEnabled", matchIfMissing = true)
public FilterRegistrationBean exceptionThrowingFilter(SleuthWebProperties webProperties) {
FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean(new ExceptionLoggingFilter());
filterRegistrationBean.setDispatcherTypes(ASYNC, ERROR, FORWARD, INCLUDE, REQUEST);
filterRegistrationBean.setOrder(TraceWebServletAutoConfiguration.TRACING_FILTER_ORDER + 1);
filterRegistrationBean.setOrder(webProperties.getFilterOrder());
return filterRegistrationBean;
}