Remove redundant SpanContextHolder access in TraceFilter

The TraceFilter should clean up its own spans. It should never
need to use the SpanContextHolder directly.

There was a test that needed it inserted instead.
This commit is contained in:
Dave Syer
2016-02-04 13:28:22 +00:00
parent 3703452626
commit 7f975c0ff8
2 changed files with 2 additions and 3 deletions

View File

@@ -36,7 +36,6 @@ import org.springframework.cloud.sleuth.event.ServerReceivedEvent;
import org.springframework.cloud.sleuth.event.ServerSentEvent;
import org.springframework.cloud.sleuth.instrument.TraceKeys;
import org.springframework.cloud.sleuth.sampler.IsTracingSampler;
import org.springframework.cloud.sleuth.trace.SpanContextHolder;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
@@ -106,8 +105,6 @@ public class TraceFilter extends OncePerRequestFilter
HttpServletResponse response, FilterChain filterChain)
throws ServletException, IOException {
// TODO: this should not be necessary
SpanContextHolder.removeCurrentSpan();
String uri = this.urlPathHelper.getPathWithinApplication(request);
boolean skip = this.skipPattern.matcher(uri).matches()
|| getHeader(request, response, Span.NOT_SAMPLED_NAME) != null;

View File

@@ -116,6 +116,8 @@ public class TraceFilterTests {
Span span = this.tracer.startTrace("foo");
this.request.setAttribute(TraceFilter.TRACE_REQUEST_ATTR, span);
// It should have been removed from the thread local context so simulate that
SpanContextHolder.removeCurrentSpan();
TraceFilter filter = new TraceFilter(this.tracer, this.traceKeys);
filter.doFilter(this.request, this.response, this.filterChain);