From 203e97681d85a526327070b753d25cd38955a648 Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Tue, 28 Jul 2015 17:56:48 +0100 Subject: [PATCH] Add request path to span name --- docs/src/main/asciidoc/README.adoc | 4 ++-- .../sleuth/instrument/web/TraceFilter.java | 7 ++++-- spring-cloud-sleuth-zipkin/docker-compose.yml | 22 +++++++++++++++++++ 3 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 spring-cloud-sleuth-zipkin/docker-compose.yml diff --git a/docs/src/main/asciidoc/README.adoc b/docs/src/main/asciidoc/README.adoc index 2deb78884..390ea5ea1 100644 --- a/docs/src/main/asciidoc/README.adoc +++ b/docs/src/main/asciidoc/README.adoc @@ -10,10 +10,10 @@ include::intro.adoc[] == Running the sample -1. Run [Zipkin](https://github.com/openzipkin/zipkin), e.g. via the docker images at [Zipkin Docker](https://github.com/openzipkin/zipkin-docker) +1. Run [Zipkin](https://github.com/openzipkin/zipkin), e.g. via docker compose (there's a `docker-compose.yml` in [Spring Cloud Sleuth](https://github.com/spring-cloud-incubator/spring-cloud-sleuth), or in [Docker Zipkin](https://github.com/openzipkin/docker-zipkin) 7. Run sample application 8. Hit `http://localhost:3380` -9. Goto `http://localhost:8080` for zipkin web +9. Goto `http://localhost:8082` for zipkin web == Building 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 e3c93bff7..65b34ea9f 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 @@ -33,6 +33,7 @@ import org.springframework.cloud.sleuth.TraceScope; import org.springframework.core.Ordered; import org.springframework.core.annotation.Order; import org.springframework.web.filter.OncePerRequestFilter; +import org.springframework.web.util.UrlPathHelper; /** * Filter that takes the value of the {@link Trace#SPAN_ID_NAME} and @@ -54,6 +55,7 @@ public class TraceFilter extends OncePerRequestFilter { private final Trace trace; private final Pattern skipPattern; + private UrlPathHelper urlPathHelper = new UrlPathHelper(); public TraceFilter(Trace trace) { this.trace = trace; @@ -77,17 +79,18 @@ public class TraceFilter extends OncePerRequestFilter { if (!skip) { String spanId = getHeader(request, response, SPAN_ID_NAME); String traceId = getHeader(request, response, TRACE_ID_NAME); + String name = "traceFilter" + this.urlPathHelper.getPathWithinApplication(request); if (hasText(spanId) && hasText(traceId)) { TraceInfo traceInfo = new TraceInfo(traceId, spanId); // TODO: trace description? - traceScope = this.trace.startSpan("traceFilter", traceInfo); + traceScope = this.trace.startSpan(name, traceInfo); // Send new span id back addToResponseIfNotPresent(response, SPAN_ID_NAME, traceScope.getSpan() .getSpanId()); } else { - traceScope = this.trace.startSpan("traceFilter"); + traceScope = this.trace.startSpan(name); } } diff --git a/spring-cloud-sleuth-zipkin/docker-compose.yml b/spring-cloud-sleuth-zipkin/docker-compose.yml new file mode 100644 index 000000000..e661e39e9 --- /dev/null +++ b/spring-cloud-sleuth-zipkin/docker-compose.yml @@ -0,0 +1,22 @@ +cassandra: + image: itszero/zipkin-cassandra +collector: + image: itszero/zipkin-collector + expose: + - 9410 + ports: + - 9410:9410 + links: + - cassandra:db +query: + image: itszero/zipkin-query + expose: + - 9411 + links: + - cassandra:db +web: + image: itszero/zipkin-web + links: + - query + ports: + - 8082:8080