Adding order for TraceFilter; fixes gh-1020

This commit is contained in:
Marcin Grzejszczak
2018-08-22 11:02:44 +02:00
parent 707f3714d6
commit e2de25f02d
3 changed files with 23 additions and 2 deletions

View File

@@ -438,6 +438,9 @@ add to the Span a tag with key `custom` and a value `tag`.
include::../../../..//spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/web/TraceFilterIntegrationTests.java[tags=response_headers,indent=0]
----
To change the order of `TraceFilter` registration, please set the
`spring.sleuth.web.filter-order` property.
=== Custom SA tag in Zipkin
Sometimes you want to create a manual Span that will wrap a call to an external service which is not instrumented.

View File

@@ -25,6 +25,12 @@ public class SleuthWebProperties {
*/
private String skipPattern = DEFAULT_SKIP_PATTERN;
/**
* Order in which the {@link TraceFilter} should be registered.
* Defaults to {@link TraceFilter#ORDER}
*/
private int filterOrder = TraceFilter.ORDER;
private Client client;
public boolean isEnabled() {
@@ -43,6 +49,18 @@ public class SleuthWebProperties {
this.skipPattern = skipPattern;
}
public static String getDefaultSkipPattern() {
return DEFAULT_SKIP_PATTERN;
}
public int getFilterOrder() {
return this.filterOrder;
}
public void setFilterOrder(int filterOrder) {
this.filterOrder = filterOrder;
}
public Client getClient() {
return this.client;
}

View File

@@ -89,12 +89,12 @@ public class TraceWebAutoConfiguration {
}
@Bean
public FilterRegistrationBean traceWebFilter(TraceFilter traceFilter) {
public FilterRegistrationBean traceWebFilter(TraceFilter traceFilter, SleuthWebProperties sleuthWebProperties) {
FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean(
traceFilter);
filterRegistrationBean.setDispatcherTypes(ASYNC, ERROR, FORWARD, INCLUDE,
REQUEST);
filterRegistrationBean.setOrder(TraceFilter.ORDER);
filterRegistrationBean.setOrder(sleuthWebProperties.getFilterOrder());
return filterRegistrationBean;
}