From e50005e5f61df2ab0188a7091c8b0f080cc98603 Mon Sep 17 00:00:00 2001 From: Marcin Grzejszczak Date: Thu, 15 Feb 2018 17:51:06 +0100 Subject: [PATCH] Fixed the build --- .../cloud/sleuth/instrument/web/TraceFilter.java | 4 ++-- .../instrument/web/TraceFilterIntegrationTests.java | 8 ++++++++ .../cloud/sleuth/instrument/web/TraceFilterTests.java | 1 - 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/web/TraceFilter.java b/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/web/TraceFilter.java index 02fa84c4c..ea6d886ad 100644 --- a/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/web/TraceFilter.java +++ b/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/web/TraceFilter.java @@ -253,9 +253,9 @@ public class TraceFilter extends GenericFilterBean { } if (!httpStatusSuccessful(response) && !hasErrorController()) { tracer().close(span); - } - if (exception == null || !hasErrorController()) { + } else if (exception == null || !hasErrorController()) { clearTraceAttribute(request); + tracer().close(span); } } else if (tracer().isTracing()) { if (log.isDebugEnabled()) { diff --git a/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/web/TraceFilterIntegrationTests.java b/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/web/TraceFilterIntegrationTests.java index ab9fa15af..e3c89f32b 100644 --- a/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/web/TraceFilterIntegrationTests.java +++ b/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/web/TraceFilterIntegrationTests.java @@ -25,6 +25,7 @@ import org.springframework.cloud.sleuth.assertions.ListOfSpans; import org.springframework.cloud.sleuth.instrument.DefaultTestAutoConfiguration; import org.springframework.cloud.sleuth.instrument.web.common.AbstractMvcIntegrationTest; import org.springframework.cloud.sleuth.sampler.AlwaysSampler; +import org.springframework.cloud.sleuth.trace.TestSpanContextHolder; import org.springframework.cloud.sleuth.util.ArrayListSpanAccumulator; import org.springframework.cloud.sleuth.util.ExceptionUtils; import org.springframework.context.annotation.Bean; @@ -74,6 +75,7 @@ public class TraceFilterIntegrationTests extends AbstractMvcIntegrationTest { .hasLoggedAnEvent(Span.SERVER_SEND); then(ExceptionUtils.getLastException()).isNull(); then(new ListOfSpans(this.spanAccumulator.getSpans())).hasServerSideSpansInProperOrder(); + then(this.tracer.getCurrentSpan()).isNull(); } @Test @@ -85,6 +87,7 @@ public class TraceFilterIntegrationTests extends AbstractMvcIntegrationTest { // we don't want to respond with any tracing data then(notSampledHeaderIsPresent(mvcResult)).isEqualTo(false); then(ExceptionUtils.getLastException()).isNull(); + then(this.tracer.getCurrentSpan()).isNull(); } @Test @@ -95,6 +98,7 @@ public class TraceFilterIntegrationTests extends AbstractMvcIntegrationTest { MvcResult mvcResult = whenSentPingWithTraceId(expectedTraceId); then(ExceptionUtils.getLastException()).isNull(); + then(this.tracer.getCurrentSpan()).isNull(); } @Test @@ -105,6 +109,7 @@ public class TraceFilterIntegrationTests extends AbstractMvcIntegrationTest { then(MDC.getCopyOfContextMap()).isEmpty(); then(ExceptionUtils.getLastException()).isNull(); + then(this.tracer.getCurrentSpan()).isNull(); } @Test @@ -135,6 +140,7 @@ public class TraceFilterIntegrationTests extends AbstractMvcIntegrationTest { then(taggedSpan.get()).hasATag("mvc.controller.class", "TestController"); then(ExceptionUtils.getLastException()).isNull(); then(new ListOfSpans(this.spanAccumulator.getSpans())).hasServerSideSpansInProperOrder(); + then(this.tracer.getCurrentSpan()).isNull(); } @Test @@ -163,6 +169,7 @@ public class TraceFilterIntegrationTests extends AbstractMvcIntegrationTest { // the ErrorController would close the span then(this.tracer.getCurrentSpan()).isNotNull(); this.tracer.close(this.tracer.getCurrentSpan()); + then(this.tracer.getCurrentSpan()).isNull(); then(this.spanAccumulator.getSpans()).hasSize(1); then(this.spanAccumulator.getSpans().get(0).tags()) .containsKey("error"); @@ -192,6 +199,7 @@ public class TraceFilterIntegrationTests extends AbstractMvcIntegrationTest { then(ExceptionUtils.getLastException()).isNull(); then(mvcResult.getResponse().getHeader("ZIPKIN-TRACE-ID")).isEqualTo(Span.idToHex(expectedTraceId)); then(new ListOfSpans(this.spanAccumulator.getSpans())).hasASpanWithTagEqualTo("custom", "tag"); + then(this.tracer.getCurrentSpan()).isNull(); } @Override diff --git a/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/web/TraceFilterTests.java b/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/web/TraceFilterTests.java index 4b716c92a..aa987ea40 100644 --- a/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/web/TraceFilterTests.java +++ b/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/web/TraceFilterTests.java @@ -17,7 +17,6 @@ package org.springframework.cloud.sleuth.instrument.web; import java.util.ArrayList; -import java.util.Optional; import java.util.Random; import java.util.regex.Pattern;