@@ -56,7 +56,7 @@ public class Span {
|
||||
|
||||
private final long begin;
|
||||
private long end = 0;
|
||||
private final SpanName name;
|
||||
private final String name;
|
||||
private final long traceId;
|
||||
private List<Long> parents = new ArrayList<>();
|
||||
private final long spanId;
|
||||
@@ -82,18 +82,18 @@ public class Span {
|
||||
this.savedSpan = savedSpan;
|
||||
}
|
||||
|
||||
public Span(long begin, long end, SpanName name, long traceId, List<Long> parents,
|
||||
public Span(long begin, long end, String name, long traceId, List<Long> parents,
|
||||
long spanId, boolean remote, boolean exportable, String processId) {
|
||||
this(begin, end, name, traceId, parents, spanId, remote, exportable, processId,
|
||||
null);
|
||||
}
|
||||
|
||||
public Span(long begin, long end, SpanName name, long traceId, List<Long> parents,
|
||||
public Span(long begin, long end, String name, long traceId, List<Long> parents,
|
||||
long spanId, boolean remote, boolean exportable, String processId,
|
||||
Span savedSpan) {
|
||||
this.begin = begin <= 0 ? System.currentTimeMillis() : begin;
|
||||
this.end = end;
|
||||
this.name = name != null ? name : SpanName.NO_NAME;
|
||||
this.name = name != null ? name : "";
|
||||
this.traceId = traceId;
|
||||
this.parents = parents;
|
||||
this.spanId = spanId;
|
||||
@@ -192,7 +192,7 @@ public class Span {
|
||||
* A human-readable name assigned to this span instance.
|
||||
* <p>
|
||||
*/
|
||||
public SpanName getName() {
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
@@ -312,7 +312,7 @@ public class Span {
|
||||
public static class SpanBuilder {
|
||||
private long begin;
|
||||
private long end;
|
||||
private SpanName name;
|
||||
private String name;
|
||||
private long traceId;
|
||||
private ArrayList<Long> parents = new ArrayList<>();
|
||||
private long spanId;
|
||||
@@ -336,7 +336,7 @@ public class Span {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Span.SpanBuilder name(SpanName name) {
|
||||
public Span.SpanBuilder name(String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -1,106 +0,0 @@
|
||||
/*
|
||||
* Copyright 2013-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.sleuth;
|
||||
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Class representing a name of the span.
|
||||
* It consists of
|
||||
* <li>
|
||||
* <ul>component - means of communication e.g. http, message</ul>
|
||||
* <ul>address - what the span is addressing e.g. /some/http/address, someQueueName</ul>
|
||||
* <ul>fragment - additional label e.g. async</ul>
|
||||
* </li>
|
||||
*
|
||||
* The template of the span name is
|
||||
*
|
||||
* <pre>component:address#fragment</pre>
|
||||
*
|
||||
* @author Marcin Grzejszczak
|
||||
*/
|
||||
public class SpanName {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
|
||||
|
||||
public static final SpanName NO_NAME = new SpanName("", "");
|
||||
|
||||
public final String component;
|
||||
public final String address;
|
||||
public final String fragment;
|
||||
|
||||
public SpanName(String component, String address) {
|
||||
this(component, address, "");
|
||||
}
|
||||
|
||||
public SpanName(String component, String address, String fragment) {
|
||||
this.component = component;
|
||||
this.address = address;
|
||||
this.fragment = fragment;
|
||||
}
|
||||
|
||||
public static SpanName fromString(String name) {
|
||||
String[] splitString = name.split(":");
|
||||
if (splitString.length < 2) {
|
||||
log.debug("Can't parse [{}]. Returning 'unknown' component and passing name to address", name);
|
||||
return new SpanName("unknown", name);
|
||||
}
|
||||
String protocol = splitString[0];
|
||||
String address = name.substring(name.indexOf(":") + 1);
|
||||
String fragment = "";
|
||||
if (address.contains("#")) {
|
||||
String[] splitSecondArg = address.split("#");
|
||||
fragment = address.substring(address.indexOf("#") + 1);
|
||||
address = splitSecondArg[0];
|
||||
}
|
||||
return new SpanName(protocol, address, fragment);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if (this.equals(NO_NAME)) {
|
||||
return "";
|
||||
}
|
||||
String baseName = this.component + ":" + this.address;
|
||||
if (StringUtils.hasText(this.fragment)) {
|
||||
return baseName + "#" + this.fragment;
|
||||
}
|
||||
return baseName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o)
|
||||
return true;
|
||||
if (o == null || getClass() != o.getClass())
|
||||
return false;
|
||||
SpanName spanName = (SpanName) o;
|
||||
return Objects.equals(this.component, spanName.component) &&
|
||||
Objects.equals(this.address, spanName.address) &&
|
||||
Objects.equals(this.fragment, spanName.fragment);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(this.component, this.address, this.fragment);
|
||||
}
|
||||
}
|
||||
@@ -55,7 +55,7 @@ public interface Tracer extends SpanAccessor {
|
||||
*
|
||||
* @param name The name field for the new span to create.
|
||||
*/
|
||||
Span startTrace(SpanName name);
|
||||
Span startTrace(String name);
|
||||
|
||||
/**
|
||||
* Creates a new Span with a specific parent. The parent might be in another
|
||||
@@ -67,7 +67,7 @@ public interface Tracer extends SpanAccessor {
|
||||
*
|
||||
* @param name The name field for the new span to create.
|
||||
*/
|
||||
Span joinTrace(SpanName name, Span parent);
|
||||
Span joinTrace(String name, Span parent);
|
||||
|
||||
/**
|
||||
* Start a new span if the sampler allows it or if we are already tracing in this
|
||||
@@ -75,7 +75,7 @@ public interface Tracer extends SpanAccessor {
|
||||
* @param name the name of the span
|
||||
* @param sampler a sampler to decide whether to create the span or not
|
||||
*/
|
||||
Span startTrace(SpanName name, Sampler sampler);
|
||||
Span startTrace(String name, Sampler sampler);
|
||||
|
||||
/**
|
||||
* Pick up an existing span from another thread.
|
||||
|
||||
@@ -20,7 +20,6 @@ import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.springframework.cloud.sleuth.Span;
|
||||
import org.springframework.cloud.sleuth.SpanName;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
|
||||
/**
|
||||
@@ -44,14 +43,11 @@ public class TraceAsyncAspect {
|
||||
|
||||
@Around("execution (@org.springframework.scheduling.annotation.Async * *.*(..))")
|
||||
public Object traceBackgroundThread(final ProceedingJoinPoint pjp) throws Throwable {
|
||||
SpanName spanName = new SpanName(ASYNC_COMPONENT,
|
||||
pjp.getTarget().getClass().getSimpleName(),
|
||||
"method=" + pjp.getSignature().getName());
|
||||
String spanName = ASYNC_COMPONENT + ":" + pjp.getTarget().getClass().getSimpleName();
|
||||
Span span = this.tracer.startTrace(spanName);
|
||||
try {
|
||||
return pjp.proceed();
|
||||
}
|
||||
finally {
|
||||
} finally {
|
||||
this.tracer.close(span);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@ package org.springframework.cloud.sleuth.instrument.async;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
import org.springframework.cloud.sleuth.Span;
|
||||
import org.springframework.cloud.sleuth.SpanName;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
|
||||
/**
|
||||
@@ -31,7 +30,7 @@ public class TraceCallable<V> extends TraceDelegate<Callable<V>> implements Call
|
||||
super(tracer, delegate);
|
||||
}
|
||||
|
||||
public TraceCallable(Tracer tracer, Callable<V> delegate, SpanName name) {
|
||||
public TraceCallable(Tracer tracer, Callable<V> delegate, String name) {
|
||||
super(tracer, delegate, name);
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package org.springframework.cloud.sleuth.instrument.async;
|
||||
|
||||
import org.springframework.cloud.sleuth.Span;
|
||||
import org.springframework.cloud.sleuth.SpanName;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
|
||||
/**
|
||||
@@ -29,14 +28,14 @@ public abstract class TraceDelegate<T> {
|
||||
|
||||
private final Tracer tracer;
|
||||
private final T delegate;
|
||||
private final SpanName name;
|
||||
private final String name;
|
||||
private final Span parent;
|
||||
|
||||
public TraceDelegate(Tracer tracer, T delegate) {
|
||||
this(tracer, delegate, null);
|
||||
}
|
||||
|
||||
public TraceDelegate(Tracer tracer, T delegate, SpanName name) {
|
||||
public TraceDelegate(Tracer tracer, T delegate, String name) {
|
||||
this.tracer = tracer;
|
||||
this.delegate = delegate;
|
||||
this.name = name;
|
||||
@@ -51,9 +50,9 @@ public abstract class TraceDelegate<T> {
|
||||
return this.tracer.joinTrace(getSpanName(), this.parent);
|
||||
}
|
||||
|
||||
protected SpanName getSpanName() {
|
||||
protected String getSpanName() {
|
||||
return this.name == null ?
|
||||
new SpanName(ASYNC_COMPONENT, Thread.currentThread().getName())
|
||||
ASYNC_COMPONENT + ":" + Thread.currentThread().getName()
|
||||
: this.name;
|
||||
}
|
||||
|
||||
@@ -65,7 +64,7 @@ public abstract class TraceDelegate<T> {
|
||||
return this.delegate;
|
||||
}
|
||||
|
||||
public SpanName getName() {
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package org.springframework.cloud.sleuth.instrument.async;
|
||||
|
||||
import org.springframework.cloud.sleuth.Span;
|
||||
import org.springframework.cloud.sleuth.SpanName;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
|
||||
/**
|
||||
@@ -29,7 +28,7 @@ public class TraceRunnable extends TraceDelegate<Runnable> implements Runnable {
|
||||
super(tracer, delegate);
|
||||
}
|
||||
|
||||
public TraceRunnable(Tracer tracer, Runnable delegate, SpanName name) {
|
||||
public TraceRunnable(Tracer tracer, Runnable delegate, String name) {
|
||||
super(tracer, delegate, name);
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,6 @@ import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import org.springframework.cloud.sleuth.SpanName;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
/**
|
||||
* A decorator class for {@link ExecutorService} to support tracing in Executors
|
||||
@@ -34,13 +33,13 @@ import org.springframework.cloud.sleuth.Tracer;
|
||||
public class TraceableExecutorService implements ExecutorService {
|
||||
final ExecutorService delegate;
|
||||
final Tracer tracer;
|
||||
private final SpanName spanName;
|
||||
private final String spanName;
|
||||
|
||||
public TraceableExecutorService(final ExecutorService delegate, final Tracer tracer) {
|
||||
this(delegate, tracer, null);
|
||||
}
|
||||
|
||||
public TraceableExecutorService(final ExecutorService delegate, final Tracer tracer, SpanName spanName) {
|
||||
public TraceableExecutorService(final ExecutorService delegate, final Tracer tracer, String spanName) {
|
||||
this.delegate = delegate;
|
||||
this.tracer = tracer;
|
||||
this.spanName = spanName;
|
||||
|
||||
@@ -6,7 +6,6 @@ import javax.annotation.PreDestroy;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.springframework.cloud.sleuth.Span;
|
||||
import org.springframework.cloud.sleuth.SpanName;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
|
||||
import com.netflix.hystrix.strategy.HystrixPlugins;
|
||||
@@ -65,8 +64,8 @@ public class SleuthHystrixConcurrencyStrategy extends HystrixConcurrencyStrategy
|
||||
span = this.tracer.continueSpan(span);
|
||||
}
|
||||
else {
|
||||
span = this.tracer.startTrace(new SpanName(HYSTRIX_COMPONENT,
|
||||
Thread.currentThread().getName()));
|
||||
span = this.tracer.startTrace(HYSTRIX_COMPONENT +
|
||||
":" + Thread.currentThread().getName());
|
||||
created = true;
|
||||
}
|
||||
try {
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package org.springframework.cloud.sleuth.instrument.hystrix;
|
||||
|
||||
import org.springframework.cloud.sleuth.Span;
|
||||
import org.springframework.cloud.sleuth.SpanName;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
|
||||
import com.netflix.hystrix.HystrixCommand;
|
||||
@@ -47,7 +46,7 @@ public abstract class TraceCommand<R> extends HystrixCommand<R> {
|
||||
|
||||
@Override
|
||||
protected R run() throws Exception {
|
||||
SpanName spanName = new SpanName(HYSTRIX_COMPONENT, getCommandKey().name());
|
||||
String spanName = HYSTRIX_COMPONENT + ":" + getCommandKey().name();
|
||||
Span span = this.tracer.joinTrace(spanName, this.parentSpan);
|
||||
try {
|
||||
return doRun();
|
||||
|
||||
@@ -3,7 +3,6 @@ package org.springframework.cloud.sleuth.instrument.messaging;
|
||||
import java.util.Random;
|
||||
|
||||
import org.springframework.cloud.sleuth.Span;
|
||||
import org.springframework.cloud.sleuth.SpanName;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.cloud.sleuth.instrument.TraceKeys;
|
||||
import org.springframework.integration.channel.AbstractMessageChannel;
|
||||
@@ -65,7 +64,7 @@ abstract class AbstractTraceChannelInterceptor extends ChannelInterceptorAdapter
|
||||
String processId = getHeader(message, Span.PROCESS_ID_NAME);
|
||||
String spanName = getHeader(message, Span.SPAN_NAME_NAME);
|
||||
if (spanName != null) {
|
||||
span.name(SpanName.fromString(spanName));
|
||||
span.name(spanName);
|
||||
}
|
||||
if (processId != null) {
|
||||
span.processId(processId);
|
||||
@@ -107,8 +106,8 @@ abstract class AbstractTraceChannelInterceptor extends ChannelInterceptorAdapter
|
||||
return name;
|
||||
}
|
||||
|
||||
SpanName getMessageChannelName(MessageChannel channel) {
|
||||
return new SpanName(MESSAGE_COMPONENT, getChannelName(channel));
|
||||
String getMessageChannelName(MessageChannel channel) {
|
||||
return MESSAGE_COMPONENT + ":" + getChannelName(channel);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@ package org.springframework.cloud.sleuth.instrument.messaging;
|
||||
import java.util.Random;
|
||||
|
||||
import org.springframework.cloud.sleuth.Span;
|
||||
import org.springframework.cloud.sleuth.SpanName;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.cloud.sleuth.instrument.TraceKeys;
|
||||
import org.springframework.cloud.sleuth.sampler.NeverSampler;
|
||||
@@ -46,12 +45,12 @@ public class TraceChannelInterceptor extends AbstractTraceChannelInterceptor {
|
||||
public Message<?> preSend(Message<?> message, MessageChannel channel) {
|
||||
Span parentSpan = getTracer().isTracing() ? getTracer().getCurrentSpan()
|
||||
: buildSpan(message);
|
||||
SpanName name = getMessageChannelName(channel);
|
||||
String name = getMessageChannelName(channel);
|
||||
Span span = startSpan(parentSpan, name, message);
|
||||
return SpanMessageHeaders.addSpanHeaders(getTraceKeys(), message, span);
|
||||
}
|
||||
|
||||
private Span startSpan(Span span, SpanName name, Message<?> message) {
|
||||
private Span startSpan(Span span, String name, Message<?> message) {
|
||||
if (span != null) {
|
||||
return getTracer().joinTrace(name, span);
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.springframework.cloud.sleuth.Span;
|
||||
import org.springframework.cloud.sleuth.SpanName;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
|
||||
/**
|
||||
@@ -48,9 +47,7 @@ public class TraceSchedulingAspect {
|
||||
|
||||
@Around("execution (@org.springframework.scheduling.annotation.Scheduled * *.*(..))")
|
||||
public Object traceBackgroundThread(final ProceedingJoinPoint pjp) throws Throwable {
|
||||
SpanName spanName = new SpanName(SCHEDULED_COMPONENT,
|
||||
pjp.getTarget().getClass().getSimpleName(),
|
||||
"method=" + pjp.getSignature().getName());
|
||||
String spanName = SCHEDULED_COMPONENT + ":" + pjp.getTarget().getClass().getSimpleName();
|
||||
Span span = this.tracer.startTrace(spanName);
|
||||
try {
|
||||
return pjp.proceed();
|
||||
|
||||
@@ -15,6 +15,10 @@
|
||||
*/
|
||||
package org.springframework.cloud.sleuth.instrument.web;
|
||||
|
||||
import javax.servlet.FilterChain;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
@@ -22,14 +26,8 @@ import java.util.Enumeration;
|
||||
import java.util.Random;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import javax.servlet.FilterChain;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.springframework.cloud.sleuth.Span;
|
||||
import org.springframework.cloud.sleuth.Span.SpanBuilder;
|
||||
import org.springframework.cloud.sleuth.SpanName;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.cloud.sleuth.event.ServerReceivedEvent;
|
||||
import org.springframework.cloud.sleuth.event.ServerSentEvent;
|
||||
@@ -119,7 +117,7 @@ public class TraceFilter extends OncePerRequestFilter
|
||||
}
|
||||
|
||||
String protocol = "http";
|
||||
SpanName name = new SpanName(protocol, uri);
|
||||
String name = protocol + ":" + uri;
|
||||
if (spanFromRequest == null) {
|
||||
if (hasHeader(request, response, Span.TRACE_ID_NAME)) {
|
||||
long traceId = Span
|
||||
@@ -135,10 +133,10 @@ public class TraceFilter extends OncePerRequestFilter
|
||||
String processId = getHeader(request, response, Span.PROCESS_ID_NAME);
|
||||
String parentName = getHeader(request, response, Span.SPAN_NAME_NAME);
|
||||
if (StringUtils.hasText(parentName)) {
|
||||
span.name(SpanName.fromString(parentName));
|
||||
span.name(parentName);
|
||||
}
|
||||
else {
|
||||
span.name(new SpanName(protocol, "/parent" + uri));
|
||||
span.name(protocol + ":" + "/parent" + uri);
|
||||
}
|
||||
if (StringUtils.hasText(processId)) {
|
||||
span.processId(processId);
|
||||
|
||||
@@ -20,7 +20,6 @@ import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.springframework.cloud.sleuth.Span;
|
||||
import org.springframework.cloud.sleuth.SpanName;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
@@ -47,7 +46,7 @@ public class TraceHandlerInterceptor implements HandlerInterceptor {
|
||||
// TODO: get trace data from request?
|
||||
// TODO: what is the description?
|
||||
String uri = this.urlPathHelper.getPathWithinApplication(request);
|
||||
SpanName spanName = new SpanName("http", uri, "interceptor=traceHandlerInterceptor");
|
||||
String spanName = "http:" + uri;
|
||||
Span span = this.tracer.startTrace(spanName);
|
||||
request.setAttribute(ATTR_NAME, span);
|
||||
return true;
|
||||
|
||||
@@ -25,7 +25,6 @@ import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Pointcut;
|
||||
import org.springframework.cloud.sleuth.SpanAccessor;
|
||||
import org.springframework.cloud.sleuth.SpanName;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.cloud.sleuth.instrument.async.TraceCallable;
|
||||
import org.springframework.web.context.request.async.WebAsyncTask;
|
||||
@@ -104,17 +103,17 @@ public class TraceWebAspect {
|
||||
if (this.accessor.isTracing()) {
|
||||
log.debug("Wrapping callable with span ["
|
||||
+ this.accessor.getCurrentSpan() + "]");
|
||||
return new TraceCallable<>(this.tracer, callable, spanName(pjp));
|
||||
return new TraceCallable<>(this.tracer, callable);
|
||||
}
|
||||
else {
|
||||
return callable;
|
||||
}
|
||||
}
|
||||
|
||||
private SpanName spanName(ProceedingJoinPoint pjp) {
|
||||
return new SpanName(ASYNC_COMPONENT,
|
||||
pjp.getTarget().getClass().getSimpleName(),
|
||||
"method=" + pjp.getSignature().getName());
|
||||
private String spanName(ProceedingJoinPoint pjp) {
|
||||
return ASYNC_COMPONENT + ":" +
|
||||
pjp.getTarget().getClass().getSimpleName() + "#" +
|
||||
"method=" + pjp.getSignature().getName();
|
||||
}
|
||||
|
||||
@Around("anyControllerOrRestControllerWithPublicWebAsyncTaskMethod()")
|
||||
|
||||
@@ -21,7 +21,6 @@ import java.util.concurrent.Callable;
|
||||
|
||||
import org.springframework.cloud.sleuth.Sampler;
|
||||
import org.springframework.cloud.sleuth.Span;
|
||||
import org.springframework.cloud.sleuth.SpanName;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.cloud.sleuth.event.SpanAcquiredEvent;
|
||||
import org.springframework.cloud.sleuth.event.SpanContinuedEvent;
|
||||
@@ -50,7 +49,7 @@ public class DefaultTracer implements Tracer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Span joinTrace(SpanName name, Span parent) {
|
||||
public Span joinTrace(String name, Span parent) {
|
||||
if (parent == null) {
|
||||
return startTrace(name);
|
||||
}
|
||||
@@ -58,12 +57,12 @@ public class DefaultTracer implements Tracer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Span startTrace(SpanName name) {
|
||||
public Span startTrace(String name) {
|
||||
return this.startTrace(name, this.defaultSampler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Span startTrace(SpanName name, Sampler sampler) {
|
||||
public Span startTrace(String name, Sampler sampler) {
|
||||
Span span;
|
||||
if (isTracing()) {
|
||||
span = createChild(getCurrentSpan(), name);
|
||||
@@ -129,7 +128,7 @@ public class DefaultTracer implements Tracer {
|
||||
return savedSpan;
|
||||
}
|
||||
|
||||
protected Span createChild(Span parent, SpanName name) {
|
||||
protected Span createChild(Span parent, String name) {
|
||||
long id = createId();
|
||||
if (parent == null) {
|
||||
Span span = Span.builder().begin(System.currentTimeMillis()).name(name)
|
||||
|
||||
@@ -1,79 +0,0 @@
|
||||
/*
|
||||
* Copyright 2013-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.sleuth;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import static org.springframework.cloud.sleuth.assertions.SleuthAssertions.then;
|
||||
|
||||
/**
|
||||
* @author Marcin Grzejszczak
|
||||
*/
|
||||
public class SpanNameTest {
|
||||
|
||||
@Test
|
||||
public void should_return_span_name_wihout_fragment_when_no_fragment_is_passed() {
|
||||
then(new SpanName("component", "address").toString())
|
||||
.isEqualTo("component:address");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_return_span_name_together_with_fragment_when_fragment_was_passed() {
|
||||
then(new SpanName("component", "address", "fragment").toString())
|
||||
.isEqualTo("component:address#fragment");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_return_empty_string_if_there_is_no_span_name() {
|
||||
then(SpanName.NO_NAME.toString()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_build_span_from_valid_string_name() {
|
||||
then(SpanName.fromString("http:/a/b/c#async"))
|
||||
.hasComponentEqualTo("http")
|
||||
.hasAddressEqualTo("/a/b/c")
|
||||
.hasFragmentEqualTo("async");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_build_span_from_a_string_with_missing_protocol() {
|
||||
then(SpanName.fromString("/a/b/c").toString())
|
||||
.isEqualTo("unknown:/a/b/c");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_build_span_from_a_string_name_with_many_separators() {
|
||||
then(SpanName.fromString("http:/a/b:/c#async:asd=123#4444"))
|
||||
.hasComponentEqualTo("http")
|
||||
.hasAddressEqualTo("/a/b:/c")
|
||||
.hasFragmentEqualTo("async:asd=123#4444");
|
||||
}
|
||||
|
||||
@Test public void should_properly_serialize_object() throws JsonProcessingException {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
String serializedName = objectMapper
|
||||
.writeValueAsString(SpanName.fromString("async:foo#method=bar"));
|
||||
|
||||
then(serializedName).isEqualTo(
|
||||
"{\"component\":\"async\",\"address\":\"foo\",\"fragment\":\"method=bar\"}");
|
||||
}
|
||||
}
|
||||
@@ -57,7 +57,7 @@ public class SpanTest {
|
||||
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
public void getAnnotationsReadOnly() {
|
||||
Span span = new Span(1, 2, new SpanName("http", "name"), 1L, Collections.<Long>emptyList(), 2L, true,
|
||||
Span span = new Span(1, 2, "http:name", 1L, Collections.<Long>emptyList(), 2L, true,
|
||||
true, "process");
|
||||
|
||||
span.tags().put("a", "b");
|
||||
@@ -65,14 +65,14 @@ public class SpanTest {
|
||||
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
public void getTimelineAnnotationsReadOnly() {
|
||||
Span span = new Span(1, 2, new SpanName("http", "name"), 1L, Collections.<Long>emptyList(), 2L, true,
|
||||
Span span = new Span(1, 2, "http:name", 1L, Collections.<Long>emptyList(), 2L, true,
|
||||
true, "process");
|
||||
|
||||
span.logs().add(new Log(1, "1"));
|
||||
}
|
||||
|
||||
@Test public void should_properly_serialize_object() throws JsonProcessingException {
|
||||
Span span = new Span(1, 2, new SpanName("http", "name"), 1L,
|
||||
Span span = new Span(1, 2, "http:name", 1L,
|
||||
Collections.<Long>emptyList(), 2L, true, true, "process");
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ package org.springframework.cloud.sleuth.assertions;
|
||||
|
||||
import org.assertj.core.api.BDDAssertions;
|
||||
import org.springframework.cloud.sleuth.Span;
|
||||
import org.springframework.cloud.sleuth.SpanName;
|
||||
|
||||
public class SleuthAssertions extends BDDAssertions {
|
||||
|
||||
@@ -14,12 +13,4 @@ public class SleuthAssertions extends BDDAssertions {
|
||||
return new SpanAssert(actual);
|
||||
}
|
||||
|
||||
public static SpanNameAssert then(SpanName actual) {
|
||||
return assertThat(actual);
|
||||
}
|
||||
|
||||
public static SpanNameAssert assertThat(SpanName actual) {
|
||||
return new SpanNameAssert(actual);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -21,7 +21,6 @@ import java.util.Objects;
|
||||
import org.assertj.core.api.AbstractAssert;
|
||||
import org.slf4j.Logger;
|
||||
import org.springframework.cloud.sleuth.Span;
|
||||
import org.springframework.cloud.sleuth.SpanName;
|
||||
|
||||
public class SpanAssert extends AbstractAssert<SpanAssert, Span> {
|
||||
|
||||
@@ -45,17 +44,7 @@ public class SpanAssert extends AbstractAssert<SpanAssert, Span> {
|
||||
return this;
|
||||
}
|
||||
|
||||
public SpanAssert hasNameNotEqualTo(SpanName name) {
|
||||
isNotNull();
|
||||
if (Objects.equals(this.actual.getName(), name)) {
|
||||
String message = String.format("Expected span's name not to be <%s> but was <%s>", name, this.actual.getName());
|
||||
log.error(message);
|
||||
failWithMessage(message);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public SpanAssert hasNameEqualTo(SpanName name) {
|
||||
public SpanAssert hasNameEqualTo(String name) {
|
||||
isNotNull();
|
||||
if (!Objects.equals(this.actual.getName(), name)) {
|
||||
String message = String.format("Expected span's name to be <%s> but it was <%s>", name, this.actual.getName());
|
||||
@@ -64,4 +53,14 @@ public class SpanAssert extends AbstractAssert<SpanAssert, Span> {
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public SpanAssert hasNameNotEqualTo(String name) {
|
||||
isNotNull();
|
||||
if (Objects.equals(this.actual.getName(), name)) {
|
||||
String message = String.format("Expected span's name NOT to be <%s> but it was <%s>", name, this.actual.getName());
|
||||
log.error(message);
|
||||
failWithMessage(message);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
/*
|
||||
* Copyright 2013-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.sleuth.assertions;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import org.assertj.core.api.AbstractAssert;
|
||||
import org.slf4j.Logger;
|
||||
import org.springframework.cloud.sleuth.SpanName;
|
||||
|
||||
public class SpanNameAssert extends AbstractAssert<SpanNameAssert, SpanName> {
|
||||
|
||||
private static final Logger log = org.slf4j.LoggerFactory
|
||||
.getLogger(SpanNameAssert.class);
|
||||
|
||||
public SpanNameAssert(SpanName actual) {
|
||||
super(actual, SpanNameAssert.class);
|
||||
}
|
||||
|
||||
public static SpanNameAssert then(SpanName actual) {
|
||||
return new SpanNameAssert(actual);
|
||||
}
|
||||
|
||||
public SpanNameAssert hasComponentEqualTo(String protocol) {
|
||||
isNotNull();
|
||||
if (!Objects.equals(this.actual.component, protocol)) {
|
||||
String message = String.format("Expected span name's component to be <%s> but was <%s>", protocol, this.actual.component);
|
||||
log.error(message);
|
||||
failWithMessage(message);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public SpanNameAssert hasAddressEqualTo(String address) {
|
||||
isNotNull();
|
||||
if (!Objects.equals(this.actual.address, address)) {
|
||||
String message = String.format("Expected span name's address to be <%s> but was <%s>", address, this.actual.address);
|
||||
log.error(message);
|
||||
failWithMessage(message);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public SpanNameAssert hasFragmentEqualTo(String fragment) {
|
||||
isNotNull();
|
||||
if (!Objects.equals(this.actual.fragment, fragment)) {
|
||||
String message = String.format("Expected span name's fragment to be <%s> but was <%s>", fragment, this.actual.fragment);
|
||||
log.error(message);
|
||||
failWithMessage(message);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,6 @@ import org.junit.runner.RunWith;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.springframework.cloud.sleuth.Span;
|
||||
import org.springframework.cloud.sleuth.SpanName;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.cloud.sleuth.instrument.async.TraceCallable;
|
||||
import org.springframework.cloud.sleuth.sampler.AlwaysSampler;
|
||||
@@ -73,7 +72,7 @@ public class TraceCallableTests {
|
||||
}
|
||||
|
||||
private Span givenSpanIsAlreadyActive() {
|
||||
return this.tracer.startTrace(new SpanName("http", "parent"));
|
||||
return this.tracer.startTrace("http:parent");
|
||||
}
|
||||
|
||||
private Callable<Span> thatRetrievesTraceFromThreadLocal() {
|
||||
|
||||
@@ -16,7 +16,6 @@ import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.springframework.cloud.sleuth.Span;
|
||||
import org.springframework.cloud.sleuth.SpanName;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.cloud.sleuth.sampler.AlwaysSampler;
|
||||
import org.springframework.cloud.sleuth.trace.DefaultTracer;
|
||||
@@ -54,7 +53,7 @@ public class TraceableExecutorServiceTests {
|
||||
@Test
|
||||
public void should_propagate_trace_id_and_set_new_span_when_traceable_executor_service_is_executed()
|
||||
throws Exception {
|
||||
Span span = this.tracer.startTrace(new SpanName("http", "PARENT"));
|
||||
Span span = this.tracer.startTrace("http:PARENT");
|
||||
CompletableFuture.allOf(runnablesExecutedViaTraceManagerableExecutorService()).get();
|
||||
this.tracer.close(span);
|
||||
|
||||
|
||||
@@ -2,6 +2,9 @@ package org.springframework.cloud.sleuth.instrument.hystrix;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import com.jayway.awaitility.Awaitility;
|
||||
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
|
||||
import com.netflix.hystrix.strategy.HystrixPlugins;
|
||||
import org.junit.After;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
@@ -10,7 +13,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.cloud.netflix.hystrix.EnableHystrix;
|
||||
import org.springframework.cloud.sleuth.Span;
|
||||
import org.springframework.cloud.sleuth.SpanName;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.cloud.sleuth.instrument.DefaultTestAutoConfiguration;
|
||||
import org.springframework.cloud.sleuth.trace.TestSpanContextHolder;
|
||||
@@ -19,10 +21,6 @@ import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import com.jayway.awaitility.Awaitility;
|
||||
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
|
||||
import com.netflix.hystrix.strategy.HystrixPlugins;
|
||||
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
import static org.springframework.cloud.sleuth.assertions.SleuthAssertions.then;
|
||||
|
||||
@@ -58,7 +56,7 @@ public class HystrixAnnotationsIntegrationTests {
|
||||
}
|
||||
|
||||
private Span givenASpanInCurrentThread() {
|
||||
Span span = this.tracer.startTrace(new SpanName("http", "existing"));
|
||||
Span span = this.tracer.startTrace("http:existing");
|
||||
this.tracer.continueSpan(span);
|
||||
return span;
|
||||
}
|
||||
@@ -112,7 +110,7 @@ public class HystrixAnnotationsIntegrationTests {
|
||||
return this.spanCaughtFromHystrixThread.get().getTraceId();
|
||||
}
|
||||
|
||||
public SpanName getSpanName() {
|
||||
public String getSpanName() {
|
||||
if (this.spanCaughtFromHystrixThread == null
|
||||
|| (this.spanCaughtFromHystrixThread.get() != null
|
||||
&& this.spanCaughtFromHystrixThread.get()
|
||||
|
||||
@@ -2,22 +2,20 @@ package org.springframework.cloud.sleuth.instrument.hystrix;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import com.netflix.hystrix.HystrixCommandProperties;
|
||||
import com.netflix.hystrix.HystrixThreadPoolProperties;
|
||||
import com.netflix.hystrix.strategy.HystrixPlugins;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
import org.springframework.cloud.sleuth.Span;
|
||||
import org.springframework.cloud.sleuth.SpanName;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.cloud.sleuth.sampler.AlwaysSampler;
|
||||
import org.springframework.cloud.sleuth.trace.DefaultTracer;
|
||||
import org.springframework.cloud.sleuth.trace.TestSpanContextHolder;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
|
||||
import com.netflix.hystrix.HystrixCommandProperties;
|
||||
import com.netflix.hystrix.HystrixThreadPoolProperties;
|
||||
import com.netflix.hystrix.strategy.HystrixPlugins;
|
||||
|
||||
import static com.netflix.hystrix.HystrixCommand.Setter.withGroupKey;
|
||||
import static com.netflix.hystrix.HystrixCommandGroupKey.Factory.asKey;
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
@@ -64,7 +62,7 @@ public class TraceCommandTests {
|
||||
}
|
||||
|
||||
private Span givenATraceIsPresentInTheCurrentThread() {
|
||||
return this.tracer.joinTrace(new SpanName("http", "test"),
|
||||
return this.tracer.joinTrace("http:test",
|
||||
Span.builder().traceId(EXPECTED_TRACE_ID).build());
|
||||
}
|
||||
|
||||
|
||||
@@ -16,11 +16,8 @@
|
||||
|
||||
package org.springframework.cloud.sleuth.instrument.messaging;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.cloud.sleuth.Span;
|
||||
import org.springframework.cloud.sleuth.SpanName;
|
||||
import org.springframework.cloud.sleuth.instrument.TraceKeys;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.simp.SimpMessageHeaderAccessor;
|
||||
@@ -29,6 +26,8 @@ import org.springframework.messaging.support.MessageBuilder;
|
||||
import org.springframework.messaging.support.MessageHeaderAccessor;
|
||||
import org.springframework.messaging.support.NativeMessageHeaderAccessor;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
@@ -39,7 +38,7 @@ public class SpanMessageHeadersTests {
|
||||
|
||||
@Test
|
||||
public void spanHeadersAdded() {
|
||||
Span span = Span.builder().name(new SpanName("http", "foo")).spanId(1L).traceId(2L).build();
|
||||
Span span = Span.builder().name("http:foo").spanId(1L).traceId(2L).build();
|
||||
Message<?> message = new GenericMessage<>("Hello World");
|
||||
message = SpanMessageHeaders.addSpanHeaders(this.traceKeys, message, span);
|
||||
assertThat(message.getHeaders()).containsKey(Span.SPAN_ID_NAME);
|
||||
@@ -47,7 +46,7 @@ public class SpanMessageHeadersTests {
|
||||
|
||||
@Test
|
||||
public void nativeSpanHeadersAdded() {
|
||||
Span span = Span.builder().name(new SpanName("http", "foo")).spanId(1L).traceId(2L).build();
|
||||
Span span = Span.builder().name("http:foo").spanId(1L).traceId(2L).build();
|
||||
MessageHeaderAccessor accessor = SimpMessageHeaderAccessor.create();
|
||||
Message<?> message = MessageBuilder.createMessage("Hello World", accessor.getMessageHeaders());
|
||||
message = SpanMessageHeaders.addSpanHeaders(this.traceKeys, message, span);
|
||||
|
||||
@@ -29,7 +29,6 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.test.IntegrationTest;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.cloud.sleuth.Span;
|
||||
import org.springframework.cloud.sleuth.SpanName;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.cloud.sleuth.event.SpanReleasedEvent;
|
||||
import org.springframework.cloud.sleuth.instrument.messaging.TraceChannelInterceptorTests.App;
|
||||
@@ -139,7 +138,7 @@ public class TraceChannelInterceptorTests implements MessageHandler {
|
||||
|
||||
@Test
|
||||
public void headerCreation() {
|
||||
Span span = this.tracer.startTrace(new SpanName("http", "testSendMessage"), new AlwaysSampler());
|
||||
Span span = this.tracer.startTrace("http:testSendMessage", new AlwaysSampler());
|
||||
this.channel.send(MessageBuilder.withPayload("hi").build());
|
||||
this.tracer.close(span);
|
||||
assertNotNull("message was null", this.message);
|
||||
@@ -155,7 +154,7 @@ public class TraceChannelInterceptorTests implements MessageHandler {
|
||||
// TODO: Refactor to parametrized test together with sending messages via channel
|
||||
@Test
|
||||
public void headerCreationViaMessagingTemplate() {
|
||||
Span span = this.tracer.startTrace(new SpanName("http", "testSendMessage"), new AlwaysSampler());
|
||||
Span span = this.tracer.startTrace("http:testSendMessage", new AlwaysSampler());
|
||||
this.messagingTemplate.send(MessageBuilder.withPayload("hi").build());
|
||||
this.tracer.close(span);
|
||||
assertNotNull("message was null", this.message);
|
||||
|
||||
@@ -25,7 +25,6 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.test.IntegrationTest;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.cloud.sleuth.Span;
|
||||
import org.springframework.cloud.sleuth.SpanName;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.cloud.sleuth.instrument.messaging.TraceContextPropagationChannelInterceptorTests.App;
|
||||
import org.springframework.cloud.sleuth.sampler.AlwaysSampler;
|
||||
@@ -66,7 +65,7 @@ public class TraceContextPropagationChannelInterceptorTests {
|
||||
@Test
|
||||
public void testSpanPropagation() {
|
||||
|
||||
Span span = this.tracer.startTrace(new SpanName("http", "testSendMessage"), new AlwaysSampler());
|
||||
Span span = this.tracer.startTrace("http:testSendMessage", new AlwaysSampler());
|
||||
this.channel.send(MessageBuilder.withPayload("hi").build());
|
||||
Long expectedSpanId = span.getSpanId();
|
||||
this.tracer.close(span);
|
||||
|
||||
@@ -8,10 +8,11 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.cloud.sleuth.Sampler;
|
||||
import org.springframework.cloud.sleuth.Span;
|
||||
import org.springframework.cloud.sleuth.SpanName;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.cloud.sleuth.instrument.DefaultTestAutoConfiguration;
|
||||
import org.springframework.cloud.sleuth.sampler.AlwaysSampler;
|
||||
import org.springframework.cloud.sleuth.trace.TestSpanContextHolder;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -41,9 +42,7 @@ public class TraceAsyncIntegrationTests {
|
||||
}
|
||||
|
||||
private Span givenASpanInCurrentThread() {
|
||||
Span span = this.tracer.startTrace(new SpanName("http", "existing"));
|
||||
this.tracer.continueSpan(span);
|
||||
return span;
|
||||
return this.tracer.startTrace("http:existing");
|
||||
}
|
||||
|
||||
private void whenAsyncProcessingTakesPlace() {
|
||||
@@ -57,8 +56,6 @@ public class TraceAsyncIntegrationTests {
|
||||
then(span)
|
||||
.hasTraceIdEqualTo(TraceAsyncIntegrationTests.this.classPerformingAsyncLogic.getTraceId())
|
||||
.hasNameNotEqualTo(TraceAsyncIntegrationTests.this.classPerformingAsyncLogic.getSpanName());
|
||||
then(TraceAsyncIntegrationTests.this.classPerformingAsyncLogic.getSpanName()).
|
||||
isEqualTo(SpanName.fromString("async:ClassPerformingAsyncLogic#method=invokeAsynchronousLogic"));
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -78,6 +75,11 @@ public class TraceAsyncIntegrationTests {
|
||||
return new ClassPerformingAsyncLogic();
|
||||
}
|
||||
|
||||
@Bean
|
||||
Sampler defaultSampler() {
|
||||
return new AlwaysSampler();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static class ClassPerformingAsyncLogic {
|
||||
@@ -96,7 +98,7 @@ public class TraceAsyncIntegrationTests {
|
||||
return this.span.get().getTraceId();
|
||||
}
|
||||
|
||||
public SpanName getSpanName() {
|
||||
public String getSpanName() {
|
||||
if (this.span.get() != null && this.span.get().getName() == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -23,7 +23,6 @@ import org.junit.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.springframework.cloud.sleuth.Sampler;
|
||||
import org.springframework.cloud.sleuth.Span;
|
||||
import org.springframework.cloud.sleuth.SpanName;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.cloud.sleuth.instrument.TraceKeys;
|
||||
import org.springframework.cloud.sleuth.sampler.AlwaysSampler;
|
||||
@@ -111,7 +110,7 @@ public class TraceFilterTests {
|
||||
|
||||
@Test
|
||||
public void continuesSpanInRequestAttr() throws Exception {
|
||||
Span span = this.tracer.startTrace(new SpanName("http", "foo"));
|
||||
Span span = this.tracer.startTrace("http:foo");
|
||||
this.request.setAttribute(TraceFilter.TRACE_REQUEST_ATTR, span);
|
||||
// It should have been removed from the thread local context so simulate that
|
||||
TestSpanContextHolder.removeCurrentSpan();
|
||||
|
||||
@@ -6,7 +6,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.sleuth.Sampler;
|
||||
import org.springframework.cloud.sleuth.Span;
|
||||
import org.springframework.cloud.sleuth.SpanName;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.cloud.sleuth.event.ArrayListSpanAccumulator;
|
||||
import org.springframework.cloud.sleuth.instrument.TraceKeys;
|
||||
@@ -46,7 +45,6 @@ public class MultipleHopsIntegrationTests extends AbstractMvcIntegrationTest {
|
||||
|
||||
await().until(() -> {
|
||||
then(this.arrayListSpanAccumulator.getSpans().stream().map(Span::getName)
|
||||
.map(SpanName::toString)
|
||||
.collect(
|
||||
toList())).containsAll(asList("http:/greeting", "message:greetings",
|
||||
"message:words", "message:counts"));
|
||||
|
||||
@@ -23,7 +23,6 @@ import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
import org.springframework.cloud.sleuth.SpanName;
|
||||
import org.springframework.cloud.sleuth.event.ClientReceivedEvent;
|
||||
import org.springframework.cloud.sleuth.sampler.AlwaysSampler;
|
||||
import org.springframework.cloud.sleuth.trace.DefaultTracer;
|
||||
@@ -55,7 +54,7 @@ public class TracePostZuulFilterTests {
|
||||
@Test
|
||||
public void filterPublishesEvent() throws Exception {
|
||||
this.filter.setApplicationEventPublisher(this.publisher);
|
||||
this.tracer.startTrace(new SpanName("http", "start"));
|
||||
this.tracer.startTrace("http:start");
|
||||
this.filter.run();
|
||||
verify(this.publisher).publishEvent(isA(ClientReceivedEvent.class));
|
||||
}
|
||||
|
||||
@@ -24,7 +24,6 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
import org.springframework.cloud.sleuth.Span;
|
||||
import org.springframework.cloud.sleuth.SpanName;
|
||||
import org.springframework.cloud.sleuth.sampler.AlwaysSampler;
|
||||
import org.springframework.cloud.sleuth.sampler.NeverSampler;
|
||||
import org.springframework.cloud.sleuth.trace.DefaultTracer;
|
||||
@@ -59,7 +58,7 @@ public class TracePreZuulFilterTests {
|
||||
|
||||
@Test
|
||||
public void filterAddsHeaders() throws Exception {
|
||||
this.tracer.startTrace(new SpanName("http", "start"));
|
||||
this.tracer.startTrace("http:start");
|
||||
this.filter.run();
|
||||
RequestContext ctx = RequestContext.getCurrentContext();
|
||||
assertThat(ctx.getZuulRequestHeaders().get(Span.TRACE_ID_NAME),
|
||||
@@ -70,7 +69,7 @@ public class TracePreZuulFilterTests {
|
||||
|
||||
@Test
|
||||
public void notSampledIfNotExportable() throws Exception {
|
||||
this.tracer.startTrace(new SpanName("http", "start"), NeverSampler.INSTANCE);
|
||||
this.tracer.startTrace("http:start", NeverSampler.INSTANCE);
|
||||
this.filter.run();
|
||||
RequestContext ctx = RequestContext.getCurrentContext();
|
||||
assertThat(ctx.getZuulRequestHeaders().get(Span.TRACE_ID_NAME),
|
||||
|
||||
@@ -25,7 +25,6 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.springframework.cloud.sleuth.Span;
|
||||
import org.springframework.cloud.sleuth.SpanName;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.cloud.sleuth.event.SpanAcquiredEvent;
|
||||
import org.springframework.cloud.sleuth.event.SpanReleasedEvent;
|
||||
@@ -49,10 +48,10 @@ import static org.mockito.Mockito.verify;
|
||||
public class DefaultTracerTests {
|
||||
|
||||
public static final String CREATE_SIMPLE_TRACE_SPAN_NAME = "createSimpleTrace";
|
||||
public static final SpanName CREATE_SIMPLE_TRACE = new SpanName("http",
|
||||
CREATE_SIMPLE_TRACE_SPAN_NAME);
|
||||
public static final SpanName IMPORTANT_WORK_1 = new SpanName("http", "important work 1");
|
||||
public static final SpanName IMPORTANT_WORK_2 = new SpanName("http", "important work 2");
|
||||
public static final String CREATE_SIMPLE_TRACE = "http" + ":" +
|
||||
CREATE_SIMPLE_TRACE_SPAN_NAME;
|
||||
public static final String IMPORTANT_WORK_1 = "http:important work 1";
|
||||
public static final String IMPORTANT_WORK_2 = "http:important work 2";
|
||||
public static final int NUM_SPANS = 3;
|
||||
private ApplicationEventPublisher publisher;
|
||||
|
||||
@@ -129,7 +128,7 @@ public class DefaultTracerTests {
|
||||
this.publisher);
|
||||
Span span = tracer.startTrace(CREATE_SIMPLE_TRACE, NeverSampler.INSTANCE);
|
||||
assertThat(span.isExportable(), is(false));
|
||||
Span child = tracer.joinTrace(new SpanName("http", CREATE_SIMPLE_TRACE_SPAN_NAME + "/child"), span);
|
||||
Span child = tracer.joinTrace(CREATE_SIMPLE_TRACE_SPAN_NAME + "/child", span);
|
||||
assertThat(child.isExportable(), is(false));
|
||||
}
|
||||
|
||||
@@ -166,7 +165,7 @@ public class DefaultTracerTests {
|
||||
assertThat(tracer.getCurrentSpan(), is(equalTo(grandParent)));
|
||||
}
|
||||
|
||||
private Span assertSpan(List<Span> spans, Long parentId, SpanName name) {
|
||||
private Span assertSpan(List<Span> spans, Long parentId, String name) {
|
||||
List<Span> found = findSpans(spans, parentId);
|
||||
assertThat("more than one span with parentId " + parentId, found.size(), is(1));
|
||||
Span span = found.get(0);
|
||||
|
||||
@@ -24,7 +24,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.context.embedded.EmbeddedServletContainerInitializedEvent;
|
||||
import org.springframework.cloud.sleuth.Span;
|
||||
import org.springframework.cloud.sleuth.SpanAccessor;
|
||||
import org.springframework.cloud.sleuth.SpanName;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.cloud.sleuth.sampler.AlwaysSampler;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
@@ -92,7 +91,7 @@ ApplicationListener<EmbeddedServletContainerInitializedEvent> {
|
||||
|
||||
@RequestMapping("/traced")
|
||||
public String traced() throws InterruptedException {
|
||||
Span span = this.tracer.startTrace(new SpanName("http", "customTraceEndpoint"),
|
||||
Span span = this.tracer.startTrace("http:customTraceEndpoint",
|
||||
new AlwaysSampler());
|
||||
int millis = this.random.nextInt(1000);
|
||||
log.info("Sleeping for {} millis", millis);
|
||||
|
||||
@@ -28,7 +28,6 @@ import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.boot.test.WebIntegrationTest;
|
||||
import org.springframework.cloud.sleuth.Span;
|
||||
import org.springframework.cloud.sleuth.SpanName;
|
||||
import org.springframework.cloud.sleuth.stream.Host;
|
||||
import org.springframework.cloud.sleuth.stream.SleuthSink;
|
||||
import org.springframework.cloud.sleuth.stream.Spans;
|
||||
@@ -63,7 +62,7 @@ public class ZipkinStreamTests extends AbstractIntegrationTest {
|
||||
|
||||
@Test
|
||||
public void should_propagate_spans_to_zipkin() {
|
||||
Span span = Span.builder().traceId(this.traceId).spanId(this.spanId).name(new SpanName("http", "test")).build();
|
||||
Span span = Span.builder().traceId(this.traceId).spanId(this.spanId).name("http:test").build();
|
||||
span.tag(getRequiredBinaryAnnotationName(), "10131");
|
||||
|
||||
this.input.send(messageWithSpan(span));
|
||||
|
||||
@@ -24,7 +24,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.context.embedded.EmbeddedServletContainerInitializedEvent;
|
||||
import org.springframework.cloud.sleuth.Span;
|
||||
import org.springframework.cloud.sleuth.SpanAccessor;
|
||||
import org.springframework.cloud.sleuth.SpanName;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.cloud.sleuth.sampler.AlwaysSampler;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
@@ -95,7 +94,7 @@ ApplicationListener<EmbeddedServletContainerInitializedEvent> {
|
||||
|
||||
@RequestMapping("/traced")
|
||||
public String traced() throws InterruptedException {
|
||||
Span span = this.tracer.startTrace(new SpanName("http", "customTraceEndpoint"),
|
||||
Span span = this.tracer.startTrace("http:customTraceEndpoint",
|
||||
new AlwaysSampler());
|
||||
int millis = this.random.nextInt(1000);
|
||||
log.info("Sleeping for {} millis", millis);
|
||||
|
||||
@@ -24,7 +24,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.context.embedded.EmbeddedServletContainerInitializedEvent;
|
||||
import org.springframework.cloud.sleuth.Span;
|
||||
import org.springframework.cloud.sleuth.SpanAccessor;
|
||||
import org.springframework.cloud.sleuth.SpanName;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.cloud.sleuth.sampler.AlwaysSampler;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
@@ -91,7 +90,7 @@ ApplicationListener<EmbeddedServletContainerInitializedEvent> {
|
||||
|
||||
@RequestMapping("/traced")
|
||||
public String traced() throws InterruptedException {
|
||||
Span span = this.tracer.startTrace(new SpanName("http", "customTraceEndpoint"),
|
||||
Span span = this.tracer.startTrace("http:customTraceEndpoint",
|
||||
new AlwaysSampler());
|
||||
int millis = this.random.nextInt(1000);
|
||||
log.info("Sleeping for {} millis", millis);
|
||||
|
||||
@@ -23,12 +23,11 @@ import java.util.Collections;
|
||||
import org.junit.Test;
|
||||
import org.springframework.boot.autoconfigure.web.ServerProperties;
|
||||
import org.springframework.cloud.sleuth.Span;
|
||||
import org.springframework.cloud.sleuth.SpanName;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class ServerPropertiesHostLocatorTests {
|
||||
Span span = new Span(1, 3, new SpanName("http", "name"), 1L, Collections.<Long>emptyList(), 2L, true, true,
|
||||
Span span = new Span(1, 3, "http:name", 1L, Collections.<Long>emptyList(), 2L, true, true,
|
||||
"process");
|
||||
|
||||
@Test
|
||||
|
||||
@@ -35,7 +35,6 @@ import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfigurati
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.cloud.sleuth.Sampler;
|
||||
import org.springframework.cloud.sleuth.Span;
|
||||
import org.springframework.cloud.sleuth.SpanName;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.cloud.sleuth.autoconfig.TraceAutoConfiguration;
|
||||
import org.springframework.cloud.sleuth.event.ClientReceivedEvent;
|
||||
@@ -76,16 +75,16 @@ public class StreamSpanListenerTests {
|
||||
|
||||
@Test
|
||||
public void acquireAndRelease() {
|
||||
Span context = this.tracer.startTrace(new SpanName("http", "foo"));
|
||||
Span context = this.tracer.startTrace("http:foo");
|
||||
this.tracer.close(context);
|
||||
assertEquals(1, this.test.spans.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rpcAnnotations() {
|
||||
Span parent = Span.builder().traceId(1L).name(new SpanName("http", "parent")).remote(true)
|
||||
Span parent = Span.builder().traceId(1L).name("http:parent").remote(true)
|
||||
.build();
|
||||
Span context = this.tracer.joinTrace(new SpanName("http", "child"), parent);
|
||||
Span context = this.tracer.joinTrace("http:child", parent);
|
||||
this.application.publishEvent(new ClientSentEvent(this, context));
|
||||
this.application
|
||||
.publishEvent(new ServerReceivedEvent(this, parent, context));
|
||||
@@ -108,7 +107,7 @@ public class StreamSpanListenerTests {
|
||||
|
||||
@Test
|
||||
public void shouldIncreaseNumberOfAcceptedSpans() {
|
||||
Span context = this.tracer.startTrace(new SpanName("http", "foo"));
|
||||
Span context = this.tracer.startTrace("http:foo");
|
||||
this.tracer.close(context);
|
||||
this.listener.poll();
|
||||
|
||||
|
||||
@@ -20,11 +20,10 @@ import java.util.NoSuchElementException;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.springframework.cloud.sleuth.Span;
|
||||
import org.springframework.cloud.sleuth.SpanName;
|
||||
import org.springframework.cloud.sleuth.stream.Host;
|
||||
import org.springframework.cloud.sleuth.stream.SleuthSink;
|
||||
import org.springframework.cloud.sleuth.stream.Spans;
|
||||
|
||||
import org.springframework.util.StringUtils;
|
||||
import zipkin.BinaryAnnotation;
|
||||
import zipkin.Constants;
|
||||
import zipkin.Endpoint;
|
||||
@@ -78,7 +77,7 @@ final class SamplingZipkinSpanIterator implements Iterator<zipkin.Span> {
|
||||
* returns a converted span or null if it is invalid or unsampled.
|
||||
*/
|
||||
zipkin.Span convertAndSample(Span input, Host host) {
|
||||
if (!protocolWithAddressMatch(input)) {
|
||||
if (!input.getName().equals("message:" + SleuthSink.INPUT)) {
|
||||
zipkin.Span result = SamplingZipkinSpanIterator.convert(input, host);
|
||||
if (this.sampler.isSampled(result.traceId)) {
|
||||
return result;
|
||||
@@ -90,12 +89,6 @@ final class SamplingZipkinSpanIterator implements Iterator<zipkin.Span> {
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean protocolWithAddressMatch(Span input) {
|
||||
SpanName spanName = input.getName();
|
||||
return SamplingZipkinSpanIterator.MESSAGE_COMPONENT.equals(spanName.component) &&
|
||||
("/" + SleuthSink.INPUT).equals(spanName.address);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a given Sleuth span to a Zipkin Span.
|
||||
* <ul>
|
||||
@@ -137,8 +130,8 @@ final class SamplingZipkinSpanIterator implements Iterator<zipkin.Span> {
|
||||
zipkinSpan.parentId(span.getParents().get(0));
|
||||
}
|
||||
zipkinSpan.id(span.getSpanId());
|
||||
if (!SpanName.NO_NAME.equals(span.getName())) {
|
||||
zipkinSpan.name(span.getName().toString());
|
||||
if (StringUtils.hasText(span.getName())) {
|
||||
zipkinSpan.name(span.getName());
|
||||
}
|
||||
return zipkinSpan.build();
|
||||
}
|
||||
|
||||
@@ -23,7 +23,6 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.cloud.sleuth.Span;
|
||||
import org.springframework.cloud.sleuth.SpanName;
|
||||
import org.springframework.cloud.sleuth.stream.Host;
|
||||
import org.springframework.cloud.sleuth.stream.Spans;
|
||||
import zipkin.Sampler;
|
||||
@@ -54,7 +53,7 @@ public class SamplingZipkinSpanIteratorTests {
|
||||
Sampler.create(1.0f), spans);
|
||||
|
||||
assertThat(result).extracting(s -> s.name).containsExactly(
|
||||
"message:/foo", "message:/bar", "message:/baz");
|
||||
"message:foo", "message:bar", "message:baz");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -74,12 +73,12 @@ public class SamplingZipkinSpanIteratorTests {
|
||||
spans);
|
||||
|
||||
assertThat(result).extracting(s -> s.name).containsExactly(
|
||||
"message:/foo", "message:/baz");
|
||||
"message:foo", "message:baz");
|
||||
}
|
||||
|
||||
Span span(String name) {
|
||||
Long id = new Random().nextLong();
|
||||
return new Span(1, 3, new SpanName("message", "/" + name), id, Collections.<Long>emptyList(), id, true, true,
|
||||
return new Span(1, 3, "message:" + name, id, Collections.<Long>emptyList(), id, true, true,
|
||||
"process");
|
||||
}
|
||||
}
|
||||
@@ -18,18 +18,16 @@ package org.springframework.cloud.sleuth.zipkin.stream;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import org.springframework.cloud.sleuth.SpanName;
|
||||
import zipkin.BinaryAnnotation;
|
||||
import zipkin.Endpoint;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.cloud.sleuth.Span;
|
||||
import org.springframework.cloud.sleuth.stream.Host;
|
||||
import zipkin.BinaryAnnotation;
|
||||
import zipkin.Endpoint;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class ZipkinMessageListenerTests {
|
||||
Span span = new Span(1, 3, new SpanName("http", "name"), 1L, Collections.<Long>emptyList(), 2L, true, true,
|
||||
Span span = new Span(1, 3, "http:name", 1L, Collections.<Long>emptyList(), 2L, true, true,
|
||||
"process");
|
||||
Host host = new Host("myservice", "1.2.3.4", 8080);
|
||||
Endpoint endpoint = Endpoint.create("myservice", 1 << 24 | 2 << 16 | 3 << 8 | 4, 8080);
|
||||
@@ -82,7 +80,7 @@ public class ZipkinMessageListenerTests {
|
||||
// TODO: "unknown" bc process id, documented as not nullable, is null in some tests.
|
||||
@Test
|
||||
public void nullProcessIdCoercesToUnknownServiceName() {
|
||||
Span noProcessId = Span.builder().traceId(1L).name(new SpanName("http", "parent")).remote(true).build();
|
||||
Span noProcessId = Span.builder().traceId(1L).name("http:parent").remote(true).build();
|
||||
|
||||
zipkin.Span result = SamplingZipkinSpanIterator.convert(noProcessId, this.host);
|
||||
|
||||
|
||||
@@ -21,7 +21,6 @@ import java.util.Map;
|
||||
|
||||
import org.springframework.cloud.sleuth.Log;
|
||||
import org.springframework.cloud.sleuth.Span;
|
||||
import org.springframework.cloud.sleuth.SpanName;
|
||||
import org.springframework.cloud.sleuth.event.ClientReceivedEvent;
|
||||
import org.springframework.cloud.sleuth.event.ClientSentEvent;
|
||||
import org.springframework.cloud.sleuth.event.ServerReceivedEvent;
|
||||
@@ -30,6 +29,7 @@ import org.springframework.cloud.sleuth.event.SpanAcquiredEvent;
|
||||
import org.springframework.cloud.sleuth.event.SpanReleasedEvent;
|
||||
import org.springframework.context.event.EventListener;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import zipkin.Annotation;
|
||||
import zipkin.BinaryAnnotation;
|
||||
@@ -150,8 +150,8 @@ public class ZipkinSpanListener {
|
||||
zipkinSpan.parentId(span.getParents().get(0));
|
||||
}
|
||||
zipkinSpan.id(span.getSpanId());
|
||||
if (!SpanName.NO_NAME.equals(span.getName())) {
|
||||
zipkinSpan.name(span.getName().toString());
|
||||
if (StringUtils.hasText(span.getName())) {
|
||||
zipkinSpan.name(span.getName());
|
||||
}
|
||||
return zipkinSpan.build();
|
||||
}
|
||||
|
||||
@@ -27,7 +27,6 @@ import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfigurati
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.cloud.sleuth.Sampler;
|
||||
import org.springframework.cloud.sleuth.Span;
|
||||
import org.springframework.cloud.sleuth.SpanName;
|
||||
import org.springframework.cloud.sleuth.Tracer;
|
||||
import org.springframework.cloud.sleuth.autoconfig.TraceAutoConfiguration;
|
||||
import org.springframework.cloud.sleuth.event.ClientReceivedEvent;
|
||||
@@ -70,7 +69,7 @@ public class ZipkinSpanListenerTests {
|
||||
this.test.spans.clear();
|
||||
}
|
||||
|
||||
Span parent = Span.builder().traceId(1L).name(new SpanName("http", "parent")).remote(true).build();
|
||||
Span parent = Span.builder().traceId(1L).name("http:parent").remote(true).build();
|
||||
|
||||
/** Sleuth timestamps are millisecond granularity while zipkin is microsecond. */
|
||||
@Test
|
||||
@@ -118,7 +117,7 @@ public class ZipkinSpanListenerTests {
|
||||
*/
|
||||
@Test
|
||||
public void spanWithoutAnnotationsLogsComponent() {
|
||||
Span context = this.tracer.startTrace(new SpanName("http", "foo"));
|
||||
Span context = this.tracer.startTrace("http:foo");
|
||||
this.tracer.close(context);
|
||||
assertEquals(1, this.test.spans.size());
|
||||
assertThat(this.test.spans.get(0).binaryAnnotations.get(0).endpoint.serviceName)
|
||||
@@ -127,7 +126,7 @@ public class ZipkinSpanListenerTests {
|
||||
|
||||
@Test
|
||||
public void rpcAnnotations() {
|
||||
Span context = this.tracer.joinTrace(new SpanName("http", "child"), this.parent);
|
||||
Span context = this.tracer.joinTrace("http:child", this.parent);
|
||||
this.application.publishEvent(new ClientSentEvent(this, context));
|
||||
this.application.publishEvent(new ServerReceivedEvent(this, this.parent, context));
|
||||
this.application.publishEvent(new ServerSentEvent(this, this.parent, context));
|
||||
|
||||
Reference in New Issue
Block a user