diff --git a/docs/src/main/asciidoc/images/dependencies.png b/docs/src/main/asciidoc/images/dependencies.png new file mode 100644 index 000000000..d0eceb6fb Binary files /dev/null and b/docs/src/main/asciidoc/images/dependencies.png differ diff --git a/docs/src/main/asciidoc/intro.adoc b/docs/src/main/asciidoc/intro.adoc index ac63b7d5b..b9b480596 100644 --- a/docs/src/main/asciidoc/intro.adoc +++ b/docs/src/main/asciidoc/intro.adoc @@ -84,6 +84,10 @@ colorful labels. How does it happen that in Zipkin 10 spans are received? So 1 span from *A*, 2 spans from *B*, 1 span from *C*, 2 spans from *D*, 1 span from *E*, 2 spans from *F* and 1 from *G*. Altogether *10* spans. +The dependency graph in Zipkin would look like this: + +image::https://raw.githubusercontent.com/spring-cloud/spring-cloud-sleuth/master/docs/src/main/asciidoc/images/dependencies.png[Dependencies] + ==== Log correlation When grepping the logs of those four applications by trace id equal to e.g. `2485ec27856c56f4` one would get the following: 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 de1b9c717..8891edb19 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 @@ -136,10 +136,12 @@ public class TraceFilter extends OncePerRequestFilter { addResponseTags(response, exception); if (spanFromRequest.hasSavedSpan()) { Span parent = spanFromRequest.getSavedSpan(); - if (parent != null && parent.isRemote()) { + if (parent.isRemote()) { parent.logEvent(Span.SERVER_SEND); this.spanReporter.report(parent); } + } else { + spanFromRequest.logEvent(Span.SERVER_SEND); } // Double close to clean up the parent (remote span as well) this.tracer.close(spanFromRequest); @@ -171,6 +173,7 @@ public class TraceFilter extends OncePerRequestFilter { else { spanFromRequest = this.tracer.createSpan(name); } + spanFromRequest.logEvent(Span.SERVER_RECV); request.setAttribute(TRACE_REQUEST_ATTR, spanFromRequest); } return spanFromRequest; 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 8465b19d6..73ca00f97 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,7 +25,7 @@ import org.springframework.test.web.servlet.setup.DefaultMockMvcBuilder; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -import static org.assertj.core.api.BDDAssertions.then; +import static org.springframework.cloud.sleuth.assertions.SleuthAssertions.then; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.asyncDispatch; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @@ -61,6 +61,7 @@ public class TraceFilterIntegrationTests extends AbstractMvcIntegrationTest { MvcResult mvcResult = whenSentPingWithoutTracingData(); then(tracingHeaderFrom(mvcResult)).isNotNull(); + then(TraceFilterIntegrationTests.span).hasLoggedAnEvent(Span.SERVER_RECV).hasLoggedAnEvent(Span.SERVER_SEND); } @Test @@ -71,7 +72,7 @@ public class TraceFilterIntegrationTests extends AbstractMvcIntegrationTest { } @Test - public void when_correlationId_is_sent_should_not_create_a_new_one_but_return_the_existing_one_instead() + public void when_traceId_is_sent_should_not_create_a_new_one_but_return_the_existing_one_instead() throws Exception { Long expectedTraceId = new Random().nextLong(); @@ -81,7 +82,7 @@ public class TraceFilterIntegrationTests extends AbstractMvcIntegrationTest { } @Test - public void when_correlationId_is_sent_to_async_endpoint_span_is_joined() + public void when_traceId_is_sent_to_async_endpoint_span_is_joined() throws Exception { Long expectedTraceId = new Random().nextLong(); @@ -115,16 +116,16 @@ public class TraceFilterIntegrationTests extends AbstractMvcIntegrationTest { return sendPingWithTraceId("/future", Span.TRACE_ID_NAME, passedTraceId); } - private MvcResult sendPingWithTraceId(String headerName, Long correlationId) + private MvcResult sendPingWithTraceId(String headerName, Long traceId) throws Exception { - return sendPingWithTraceId("/ping", headerName, correlationId); + return sendPingWithTraceId("/ping", headerName, traceId); } private MvcResult sendPingWithTraceId(String path, String headerName, - Long correlationId) throws Exception { + Long traceId) throws Exception { return this.mockMvc .perform(MockMvcRequestBuilders.get(path).accept(MediaType.TEXT_PLAIN) - .header(headerName, Span.idToHex(correlationId)) + .header(headerName, Span.idToHex(traceId)) .header(Span.SPAN_ID_NAME, Span.idToHex(new Random().nextLong()))) .andReturn(); }