Commit d3e2e22f authored by Colin Harrington's avatar Colin Harrington Committed by Stephane Nicoll

Add the ability to disable the trace filter

See gh-8650
parent fccab427
/*
* Copyright 2012-2016 the original author or authors.
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -28,6 +28,7 @@ import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.web.ErrorAttributes;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
......@@ -42,6 +43,7 @@ import org.springframework.web.servlet.DispatcherServlet;
*/
@ConditionalOnClass({ Servlet.class, DispatcherServlet.class, ServletRegistration.class })
@AutoConfigureAfter(TraceRepositoryAutoConfiguration.class)
@ConditionalOnProperty(name = "endpoints.trace.filter.enabled", matchIfMissing = true)
@EnableConfigurationProperties(TraceProperties.class)
@Configuration
public class TraceWebFilterAutoConfiguration {
......
......@@ -24,6 +24,7 @@ import org.springframework.boot.actuate.trace.TraceProperties;
import org.springframework.boot.actuate.trace.TraceRepository;
import org.springframework.boot.actuate.trace.WebRequestTraceFilter;
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
......@@ -58,6 +59,19 @@ public class TraceWebFilterAutoConfigurationTests {
context.close();
}
@Test
public void skipsFilterIfPropertyDisabled() throws Exception {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(context,
"endpoints.trace.filter.enabled:false");
context.register(PropertyPlaceholderAutoConfiguration.class,
TraceRepositoryAutoConfiguration.class,
TraceWebFilterAutoConfiguration.class);
context.refresh();
assertThat(context.getBeansOfType(WebRequestTraceFilter.class).size()).isEqualTo(0);
context.close();
}
@Configuration
static class CustomTraceFilterConfig {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment