Change a few names of things

KV annotations are just "annotations", and the "start" and "stop"
annotations in zipkin are "acquire" and "release" (since, in
particular the latter can in principle happen more than once
and not necessarily the last thing that happens to a span).

TODO: decide if TraceContextHolder is really holding a Span
or a TraceContext (or TraceScope). Maybe think of a better
name for TraceScope.
This commit is contained in:
Dave Syer
2015-08-16 10:05:05 +01:00
parent 6fa9408e76
commit 8d2efdb9a9
12 changed files with 46 additions and 46 deletions

View File

@@ -94,7 +94,7 @@ public class MilliSpan implements Span {
}
@Override
public void addKVAnnotation(String key, String value) {
public void addAnnotation(String key, String value) {
this.kVAnnotations.put(key, value);
}

View File

@@ -99,7 +99,7 @@ public interface Span {
/**
* Add a data annotation associated with this span
*/
void addKVAnnotation(String key, String value);
void addAnnotation(String key, String value);
/**
* Add a timeline annotation associated with this span
@@ -112,7 +112,7 @@ public interface Span {
* <p/>
* Will never be null.
*/
Map<String, String> getKVAnnotations();
Map<String, String> getAnnotations();
/**
* Get any timeline annotations (read only)

View File

@@ -22,7 +22,7 @@ import lombok.SneakyThrows;
import lombok.Value;
import lombok.experimental.NonFinal;
import org.springframework.cloud.sleuth.event.SpanStoppedEvent;
import org.springframework.cloud.sleuth.event.SpanReleasedEvent;
import org.springframework.cloud.sleuth.util.ExceptionUtils;
import org.springframework.context.ApplicationEventPublisher;
@@ -99,11 +99,11 @@ public class TraceScope implements Closeable {
this.span.stop();
if (this.savedSpan != null
&& this.span.getParents().contains(this.savedSpan.getSpanId())) {
this.publisher.publishEvent(new SpanStoppedEvent(this, this.savedSpan,
this.publisher.publishEvent(new SpanReleasedEvent(this, this.savedSpan,
this.span));
}
else {
this.publisher.publishEvent(new SpanStoppedEvent(this, this.span));
this.publisher.publishEvent(new SpanReleasedEvent(this, this.span));
}
TraceContextHolder.setCurrentSpan(this.savedSpan);
}

View File

@@ -27,11 +27,11 @@ import org.springframework.context.ApplicationListener;
* @author Spencer Gibb
*/
@Value
public class ArrayListSpanAccumulator implements ApplicationListener<SpanStoppedEvent> {
public class ArrayListSpanAccumulator implements ApplicationListener<SpanReleasedEvent> {
private final ArrayList<Span> spans = new ArrayList<>();
@Override
public void onApplicationEvent(SpanStoppedEvent event) {
public void onApplicationEvent(SpanReleasedEvent event) {
spans.add(event.getSpan());
}
}

View File

@@ -28,16 +28,16 @@ import org.springframework.context.ApplicationEvent;
@Data
@EqualsAndHashCode(callSuper=false)
@SuppressWarnings("serial")
public class SpanStartedEvent extends ApplicationEvent {
public class SpanAcquiredEvent extends ApplicationEvent {
private final Span parent;
private final Span span;
public SpanStartedEvent(Object source, Span span) {
public SpanAcquiredEvent(Object source, Span span) {
this(source, null, span);
}
public SpanStartedEvent(Object source, Span parent, Span span) {
public SpanAcquiredEvent(Object source, Span parent, Span span) {
super(source);
this.parent = parent;
this.span = span;

View File

@@ -28,16 +28,16 @@ import org.springframework.context.ApplicationEvent;
@Data
@EqualsAndHashCode(callSuper=false)
@SuppressWarnings("serial")
public class SpanStoppedEvent extends ApplicationEvent {
public class SpanReleasedEvent extends ApplicationEvent {
private final Span span;
private final Span parent;
public SpanStoppedEvent(Object source, Span span) {
public SpanReleasedEvent(Object source, Span span) {
this(source, null, span);
}
public SpanStoppedEvent(Object source, Span parent, Span span) {
public SpanReleasedEvent(Object source, Span parent, Span span) {
super(source);
this.parent = parent;
this.span = span;

View File

@@ -20,7 +20,7 @@ import lombok.Data;
import lombok.SneakyThrows;
import lombok.extern.apachecommons.CommonsLog;
import org.springframework.cloud.sleuth.event.SpanStoppedEvent;
import org.springframework.cloud.sleuth.event.SpanReleasedEvent;
import org.springframework.context.event.EventListener;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
@@ -46,9 +46,9 @@ public class JsonLogSpanListener {
}
@SneakyThrows
@EventListener(SpanStoppedEvent.class)
@EventListener(SpanReleasedEvent.class)
@Order(Ordered.LOWEST_PRECEDENCE-10)
public void stop(SpanStoppedEvent event) {
public void stop(SpanReleasedEvent event) {
log.info(this.prefix + this.objectMapper.writeValueAsString(event.getSpan()) +
this.suffix);
}

View File

@@ -24,8 +24,8 @@ import org.slf4j.MDC;
import org.springframework.cloud.sleuth.Span;
import org.springframework.cloud.sleuth.Trace;
import org.springframework.cloud.sleuth.event.SpanContinuedEvent;
import org.springframework.cloud.sleuth.event.SpanStartedEvent;
import org.springframework.cloud.sleuth.event.SpanStoppedEvent;
import org.springframework.cloud.sleuth.event.SpanAcquiredEvent;
import org.springframework.cloud.sleuth.event.SpanReleasedEvent;
import org.springframework.context.event.EventListener;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
@@ -36,9 +36,9 @@ import org.springframework.core.annotation.Order;
@Slf4j
public class Slf4jSpanListener {
@EventListener(SpanStartedEvent.class)
@EventListener(SpanAcquiredEvent.class)
@Order(Ordered.LOWEST_PRECEDENCE)
public void start(SpanStartedEvent event) {
public void start(SpanAcquiredEvent event) {
Span span = event.getSpan();
MDC.put(Trace.SPAN_ID_NAME, span.getSpanId());
MDC.put(Trace.TRACE_ID_NAME, span.getTraceId());
@@ -59,9 +59,9 @@ public class Slf4jSpanListener {
log.info("Continued span: {}", event.getSpan());
}
@EventListener(SpanStoppedEvent.class)
@EventListener(SpanReleasedEvent.class)
@Order(Ordered.LOWEST_PRECEDENCE)
public void stop(SpanStoppedEvent event) {
public void stop(SpanReleasedEvent event) {
// TODO: what should this log level be?
log.info("Stopped span: {}", event.getSpan());
if (event.getParent() != null) {

View File

@@ -29,7 +29,7 @@ import org.springframework.cloud.sleuth.Trace;
import org.springframework.cloud.sleuth.TraceContextHolder;
import org.springframework.cloud.sleuth.TraceScope;
import org.springframework.cloud.sleuth.event.SpanContinuedEvent;
import org.springframework.cloud.sleuth.event.SpanStartedEvent;
import org.springframework.cloud.sleuth.event.SpanAcquiredEvent;
import org.springframework.cloud.sleuth.instrument.TraceCallable;
import org.springframework.cloud.sleuth.instrument.TraceRunnable;
import org.springframework.context.ApplicationEventPublisher;
@@ -88,7 +88,7 @@ public class DefaultTrace implements Trace {
MilliSpan span = MilliSpan.builder().begin(System.currentTimeMillis()).name(name)
.traceId(this.idGenerator.create()).spanId(this.idGenerator.create())
.build();
this.publisher.publishEvent(new SpanStartedEvent(this, span));
this.publisher.publishEvent(new SpanAcquiredEvent(this, span));
return span;
}
else {
@@ -96,7 +96,7 @@ public class DefaultTrace implements Trace {
.traceId(parent.getTraceId()).parent(parent.getSpanId())
.spanId(this.idGenerator.create()).processId(parent.getProcessId())
.build();
this.publisher.publishEvent(new SpanStartedEvent(this, parent, span));
this.publisher.publishEvent(new SpanAcquiredEvent(this, parent, span));
return span;
}
}
@@ -120,7 +120,7 @@ public class DefaultTrace implements Trace {
public void addKVAnnotation(String key, String value) {
Span s = getCurrentSpan();
if (s != null) {
s.addKVAnnotation(key, value);
s.addAnnotation(key, value);
}
}

View File

@@ -29,8 +29,8 @@ import java.util.List;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.springframework.cloud.sleuth.event.SpanStartedEvent;
import org.springframework.cloud.sleuth.event.SpanStoppedEvent;
import org.springframework.cloud.sleuth.event.SpanAcquiredEvent;
import org.springframework.cloud.sleuth.event.SpanReleasedEvent;
import org.springframework.cloud.sleuth.sampler.AlwaysSampler;
import org.springframework.cloud.sleuth.sampler.IsTracingSampler;
import org.springframework.cloud.sleuth.trace.DefaultTrace;
@@ -62,8 +62,8 @@ public class DefaultTraceTests {
scope.close();
}
verify(publisher, times(NUM_SPANS)).publishEvent(isA(SpanStartedEvent.class));
verify(publisher, times(NUM_SPANS)).publishEvent(isA(SpanStoppedEvent.class));
verify(publisher, times(NUM_SPANS)).publishEvent(isA(SpanAcquiredEvent.class));
verify(publisher, times(NUM_SPANS)).publishEvent(isA(SpanReleasedEvent.class));
ArgumentCaptor<ApplicationEvent> captor = ArgumentCaptor
.forClass(ApplicationEvent.class);
@@ -71,8 +71,8 @@ public class DefaultTraceTests {
List<Span> spans = new ArrayList<>();
for (ApplicationEvent event : captor.getAllValues()) {
if (event instanceof SpanStoppedEvent) {
spans.add(((SpanStoppedEvent) event).getSpan());
if (event instanceof SpanReleasedEvent) {
spans.add(((SpanReleasedEvent) event).getSpan());
}
}

View File

@@ -23,7 +23,7 @@ import org.junit.Test;
import org.springframework.boot.test.OutputCapture;
import org.springframework.cloud.sleuth.MilliSpan;
import org.springframework.cloud.sleuth.Span;
import org.springframework.cloud.sleuth.event.SpanStoppedEvent;
import org.springframework.cloud.sleuth.event.SpanReleasedEvent;
import org.springframework.util.StringUtils;
import java.io.IOException;
@@ -46,9 +46,9 @@ public class JsonLogSpanListenerTests {
.begin(1)
.end(10)
.build();
span.addKVAnnotation("myKey", "myVal");
span.addAnnotation("myKey", "myVal");
span.addTimelineAnnotation("myTimelineAnnotation");
listener.stop(new SpanStoppedEvent(this, span));
listener.stop(new SpanReleasedEvent(this, span));
String output = this.output.toString().trim();
assertTrue("output doesn't contain prefix", output.contains(listener.getPrefix()));

View File

@@ -33,8 +33,8 @@ import org.springframework.cloud.sleuth.Span;
import org.springframework.cloud.sleuth.TimelineAnnotation;
import org.springframework.cloud.sleuth.event.ClientReceivedEvent;
import org.springframework.cloud.sleuth.event.ClientSentEvent;
import org.springframework.cloud.sleuth.event.SpanStartedEvent;
import org.springframework.cloud.sleuth.event.SpanStoppedEvent;
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;
@@ -64,11 +64,11 @@ public class ZipkinSpanListener {
@EventListener
@Order(0)
public void start(SpanStartedEvent event) {
public void start(SpanAcquiredEvent event) {
if (event.getParent() != null && event.getParent().isRemote()) {
event.getParent().addTimelineAnnotation(zipkinCoreConstants.SERVER_RECV);
}
event.getSpan().addTimelineAnnotation("start");
event.getSpan().addTimelineAnnotation("acquire");
}
@EventListener
@@ -85,21 +85,21 @@ public class ZipkinSpanListener {
@EventListener
@Order(0)
public void stop(SpanStoppedEvent event) {
public void release(SpanReleasedEvent event) {
if (event.getParent() != null && event.getParent().isRemote()) {
event.getParent().addTimelineAnnotation(zipkinCoreConstants.SERVER_SEND);
this.spanCollector.collect(convert(event.getParent()));
}
event.getSpan().addTimelineAnnotation("stop");
event.getSpan().addTimelineAnnotation("release");
this.spanCollector.collect(convert(event.getSpan()));
}
/**
* Converts a given Sleuth span to a Zipkin Span.
* <ul>
* <li>Set id's, etc [TraceId's etc]
* <li>Create timeline annotations based on data from HTrace Span object.
* <li>Create binary annotations based on data from HTrace Span object.
* <li>Set ids, etc
* <li>Create timeline annotations based on data from Span object.
* <li>Create binary annotations based on data from Span object.
* </ul>
*/
public com.twitter.zipkin.gen.Span convert(Span span) {
@@ -212,7 +212,7 @@ public class ZipkinSpanListener {
private List<BinaryAnnotation> createZipkinBinaryAnnotations(Span span,
Endpoint endpoint) {
List<BinaryAnnotation> l = new ArrayList<>();
for (Map.Entry<String, String> e : span.getKVAnnotations().entrySet()) {
for (Map.Entry<String, String> e : span.getAnnotations().entrySet()) {
BinaryAnnotation binaryAnn = new BinaryAnnotation();
binaryAnn.setAnnotation_type(AnnotationType.BYTES);
binaryAnn.setKey(e.getKey());