use TraceInfo instead of creating a bogus parent span

This commit is contained in:
Spencer Gibb
2015-06-26 13:48:30 -06:00
parent a4e92c2c38
commit 17f27a4cce
2 changed files with 9 additions and 22 deletions

View File

@@ -20,7 +20,6 @@ import static org.springframework.cloud.sleuth.Trace.TRACE_ID_NAME;
import static org.springframework.util.StringUtils.hasText;
import java.io.IOException;
import java.util.Collections;
import java.util.regex.Pattern;
import javax.servlet.FilterChain;
@@ -28,9 +27,8 @@ import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.cloud.sleuth.MilliSpan;
import org.springframework.cloud.sleuth.Span;
import org.springframework.cloud.sleuth.Trace;
import org.springframework.cloud.sleuth.TraceInfo;
import org.springframework.cloud.sleuth.TraceScope;
import org.springframework.web.filter.OncePerRequestFilter;
@@ -78,16 +76,12 @@ public class TraceFilter extends OncePerRequestFilter {
String traceId = getHeader(request, response, TRACE_ID_NAME);
if (hasText(spanId) && hasText(traceId)) {
Span span = MilliSpan.builder()
.traceId(traceId)
.parents(Collections.singletonList(spanId))
// TODO: use parent() when lombok plugin supports it
.build();
TraceInfo traceInfo = new TraceInfo(traceId, spanId);
// TODO: trace description?
traceScope = trace.startSpan("traceFilter", traceInfo);
// Send new span id back
addToResponseIfNotPresent(response, SPAN_ID_NAME, span.getSpanId());
//TODO: trace description?
traceScope = trace.startSpan("traceFilter", span);
addToResponseIfNotPresent(response, SPAN_ID_NAME, traceScope.getSpan()
.getSpanId());
}
else {
traceScope = trace.startSpan("traceFilter");

View File

@@ -4,13 +4,10 @@ import static org.springframework.cloud.sleuth.Trace.SPAN_ID_NAME;
import static org.springframework.cloud.sleuth.Trace.TRACE_ID_NAME;
import static org.springframework.util.StringUtils.hasText;
import java.util.Collections;
import javax.servlet.http.HttpServletRequest;
import org.springframework.cloud.sleuth.MilliSpan;
import org.springframework.cloud.sleuth.Span;
import org.springframework.cloud.sleuth.Trace;
import org.springframework.cloud.sleuth.TraceInfo;
import org.springframework.cloud.sleuth.TraceScope;
import com.netflix.zuul.ZuulFilter;
@@ -52,13 +49,9 @@ public class TracePreFilter extends ZuulFilter {
TraceScope traceScope = null;
if (hasText(spanId) && hasText(traceId)) {
Span span = MilliSpan.builder().traceId(traceId)
.parents(Collections.singletonList(spanId))
// TODO: use parent() when lombok plugin supports it
.build();
TraceInfo traceInfo = new TraceInfo(traceId, spanId);
// TODO: trace description?
traceScope = trace.startSpan("traceZuulFilter", span);
traceScope = trace.startSpan("traceZuulFilter", traceInfo);
}
else {
traceScope = trace.startSpan("traceZuulFilter");