Move configuration of TraceEndpoint
See gh-10263
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.actuate.autoconfigure.trace;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.boot.actuate.trace.Include;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
/**
|
||||
* Configuration properties for tracing.
|
||||
*
|
||||
* @author Wallace Wadge
|
||||
* @author Phillip Webb
|
||||
* @author Venil Noronha
|
||||
* @author Madhura Bhave
|
||||
* @author Stephane Nicoll
|
||||
* @since 1.3.0
|
||||
*/
|
||||
@ConfigurationProperties(prefix = "management.trace")
|
||||
public class TraceEndpointProperties {
|
||||
|
||||
/**
|
||||
* Items to be included in the trace. Defaults to request/response headers (including
|
||||
* cookies) and errors.
|
||||
*/
|
||||
private Set<Include> include = new HashSet<>(Include.defaultIncludes());
|
||||
|
||||
public Set<Include> getInclude() {
|
||||
return this.include;
|
||||
}
|
||||
|
||||
public void setInclude(Set<Include> include) {
|
||||
this.include = include;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -19,9 +19,7 @@ package org.springframework.boot.actuate.autoconfigure.trace;
|
||||
import javax.servlet.Servlet;
|
||||
import javax.servlet.ServletRegistration;
|
||||
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.ObjectProvider;
|
||||
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.AutoConfigureAfter;
|
||||
@@ -46,28 +44,28 @@ import org.springframework.web.servlet.DispatcherServlet;
|
||||
@ConditionalOnClass({ Servlet.class, DispatcherServlet.class, ServletRegistration.class })
|
||||
@AutoConfigureAfter(TraceRepositoryAutoConfiguration.class)
|
||||
@ConditionalOnProperty(prefix = "management.trace.filter", name = "enabled", matchIfMissing = true)
|
||||
@EnableConfigurationProperties(TraceProperties.class)
|
||||
@EnableConfigurationProperties(TraceEndpointProperties.class)
|
||||
public class TraceWebFilterAutoConfiguration {
|
||||
|
||||
private final TraceRepository traceRepository;
|
||||
|
||||
private final TraceProperties traceProperties;
|
||||
private final TraceEndpointProperties endpointProperties;
|
||||
|
||||
private final ErrorAttributes errorAttributes;
|
||||
|
||||
public TraceWebFilterAutoConfiguration(TraceRepository traceRepository,
|
||||
TraceProperties traceProperties,
|
||||
TraceEndpointProperties endpointProperties,
|
||||
ObjectProvider<ErrorAttributes> errorAttributes) {
|
||||
this.traceRepository = traceRepository;
|
||||
this.traceProperties = traceProperties;
|
||||
this.endpointProperties = endpointProperties;
|
||||
this.errorAttributes = errorAttributes.getIfAvailable();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public WebRequestTraceFilter webRequestLoggingFilter(BeanFactory beanFactory) {
|
||||
public WebRequestTraceFilter webRequestLoggingFilter() {
|
||||
WebRequestTraceFilter filter = new WebRequestTraceFilter(this.traceRepository,
|
||||
this.traceProperties);
|
||||
this.endpointProperties.getInclude());
|
||||
if (this.errorAttributes != null) {
|
||||
filter.setErrorAttributes(this.errorAttributes);
|
||||
}
|
||||
|
||||
@@ -21,7 +21,6 @@ import java.util.Map;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
|
||||
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;
|
||||
@@ -91,7 +90,7 @@ public class TraceWebFilterAutoConfigurationTests {
|
||||
|
||||
@Bean
|
||||
public TestWebRequestTraceFilter testWebRequestTraceFilter(
|
||||
TraceRepository repository, TraceProperties properties) {
|
||||
TraceRepository repository, TraceEndpointProperties properties) {
|
||||
return new TestWebRequestTraceFilter(repository, properties);
|
||||
}
|
||||
|
||||
@@ -100,8 +99,8 @@ public class TraceWebFilterAutoConfigurationTests {
|
||||
static class TestWebRequestTraceFilter extends WebRequestTraceFilter {
|
||||
|
||||
TestWebRequestTraceFilter(TraceRepository repository,
|
||||
TraceProperties properties) {
|
||||
super(repository, properties);
|
||||
TraceEndpointProperties properties) {
|
||||
super(repository, properties.getInclude());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user