Add request path to span name
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
22
spring-cloud-sleuth-zipkin/docker-compose.yml
Normal file
22
spring-cloud-sleuth-zipkin/docker-compose.yml
Normal file
@@ -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
|
||||
Reference in New Issue
Block a user