From 2348cf17cc9e2b0d4663b72c1d2f42e39fdc93f9 Mon Sep 17 00:00:00 2001 From: Marcin Grzejszczak Date: Tue, 16 Mar 2021 12:57:10 +0100 Subject: [PATCH] Disable double tracing filter regsitration without this change we're registering the TracingFilter twice. Once, since it's a bean and second time via the FilterRegistrationBean. with this change we're not registering the TracingFilter as a bean. It's been final so nobody could actually extend it so we're not breaking the compatibility. fixes gh-1839 --- .../instrument/web/TraceWebServletConfiguration.java | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/spring-cloud-sleuth-autoconfigure/src/main/java/org/springframework/cloud/sleuth/autoconfig/instrument/web/TraceWebServletConfiguration.java b/spring-cloud-sleuth-autoconfigure/src/main/java/org/springframework/cloud/sleuth/autoconfig/instrument/web/TraceWebServletConfiguration.java index a9416f344..1c0e73d5f 100644 --- a/spring-cloud-sleuth-autoconfigure/src/main/java/org/springframework/cloud/sleuth/autoconfig/instrument/web/TraceWebServletConfiguration.java +++ b/spring-cloud-sleuth-autoconfigure/src/main/java/org/springframework/cloud/sleuth/autoconfig/instrument/web/TraceWebServletConfiguration.java @@ -28,7 +28,6 @@ import javax.servlet.ServletResponse; import org.springframework.beans.factory.BeanFactory; 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.condition.ConditionalOnWebApplication; import org.springframework.boot.web.servlet.FilterRegistrationBean; @@ -79,12 +78,6 @@ class TraceWebServletConfiguration { return filterRegistrationBean; } - @Bean - @ConditionalOnMissingBean - TracingFilter tracingFilter(CurrentTraceContext currentTraceContext, HttpServerHandler httpServerHandler) { - return TracingFilter.create(currentTraceContext, httpServerHandler); - } - /** * Nested config that configures Web MVC if it's present (without adding a runtime * dependency to it). @@ -128,7 +121,8 @@ final class LazyTracingFilter implements Filter { private Filter tracingFilter() { if (this.tracingFilter == null) { - this.tracingFilter = this.beanFactory.getBean(TracingFilter.class); + this.tracingFilter = TracingFilter.create(this.beanFactory.getBean(CurrentTraceContext.class), + this.beanFactory.getBean(HttpServerHandler.class)); } return this.tracingFilter; }