Rename some of the core API concepts
E.g. annotation -> tag, timelineAnnotation -> log See gh-98
This commit is contained in:
@@ -24,12 +24,12 @@ import lombok.RequiredArgsConstructor;
|
||||
*/
|
||||
@Data
|
||||
@RequiredArgsConstructor
|
||||
public class TimelineAnnotation {
|
||||
public class Log {
|
||||
private final long time;
|
||||
private final String msg;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private TimelineAnnotation() {
|
||||
private Log() {
|
||||
this.time = 0;
|
||||
this.msg = null;
|
||||
}
|
||||
@@ -41,10 +41,10 @@ public class MilliSpan implements Span {
|
||||
private final String spanId;
|
||||
private boolean remote = false;
|
||||
private boolean exportable = true;
|
||||
private final Map<String, String> annotations = new LinkedHashMap<>();
|
||||
private final Map<String, String> tags = new LinkedHashMap<>();
|
||||
private final String processId;
|
||||
@Singular
|
||||
private final List<TimelineAnnotation> timelineAnnotations = new ArrayList<>();
|
||||
private final List<Log> logs = new ArrayList<>();
|
||||
|
||||
public static MilliSpan.MilliSpanBuilder builder() {
|
||||
return new MilliSpan().toBuilder();
|
||||
@@ -99,24 +99,24 @@ public class MilliSpan implements Span {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addAnnotation(String key, String value) {
|
||||
this.annotations.put(key, value);
|
||||
public void tag(String key, String value) {
|
||||
this.tags.put(key, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addTimelineAnnotation(String msg) {
|
||||
this.timelineAnnotations.add(new TimelineAnnotation(System.currentTimeMillis(),
|
||||
public void log(String msg) {
|
||||
this.logs.add(new Log(System.currentTimeMillis(),
|
||||
msg));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> getAnnotations() {
|
||||
return Collections.unmodifiableMap(this.annotations);
|
||||
public Map<String, String> tags() {
|
||||
return Collections.unmodifiableMap(this.tags);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TimelineAnnotation> getTimelineAnnotations() {
|
||||
return Collections.unmodifiableList(this.timelineAnnotations);
|
||||
public List<Log> logs() {
|
||||
return Collections.unmodifiableList(this.logs);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Base interface for gathering and reporting statistics about a block of execution.
|
||||
* Interface for gathering and reporting statistics about a block of execution.
|
||||
* <p/>
|
||||
* Spans should form a directed acyclic graph structure. It should be possible to keep
|
||||
* following the parents of a span until you arrive at a span with no parents.
|
||||
@@ -103,28 +103,28 @@ public interface Span {
|
||||
boolean isExportable();
|
||||
|
||||
/**
|
||||
* Add a data annotation associated with this span
|
||||
* Add a tag or data annotation associated with this span
|
||||
*/
|
||||
void addAnnotation(String key, String value);
|
||||
void tag(String key, String value);
|
||||
|
||||
/**
|
||||
* Add a timeline annotation associated with this span
|
||||
* Add a log or timeline annotation associated with this span
|
||||
*/
|
||||
void addTimelineAnnotation(String msg);
|
||||
void log(String msg);
|
||||
|
||||
/**
|
||||
* Get data associated with this span (read only)
|
||||
* Get tag data associated with this span (read only)
|
||||
* <p/>
|
||||
* <p/>
|
||||
* Will never be null.
|
||||
*/
|
||||
Map<String, String> getAnnotations();
|
||||
Map<String, String> tags();
|
||||
|
||||
/**
|
||||
* Get any timeline annotations (read only)
|
||||
* Get any logs or annotations (read only)
|
||||
* <p/>
|
||||
* <p/>
|
||||
* Will never be null.
|
||||
*/
|
||||
List<TimelineAnnotation> getTimelineAnnotations();
|
||||
List<Log> logs();
|
||||
}
|
||||
|
||||
@@ -23,6 +23,9 @@ import lombok.Value;
|
||||
import lombok.experimental.NonFinal;
|
||||
|
||||
/**
|
||||
* A wrapper around the current span with context for a possible hierarchy or stack of
|
||||
* spans being monitored.
|
||||
*
|
||||
* @author Spencer Gibb
|
||||
*/
|
||||
@Value
|
||||
@@ -44,7 +47,7 @@ public class Trace {
|
||||
public static final String SPAN_EXPORT_NAME = "X-Span-Export";
|
||||
|
||||
public static final List<String> HEADERS = Arrays.asList(SPAN_ID_NAME, TRACE_ID_NAME,
|
||||
SPAN_NAME_NAME, PARENT_ID_NAME, PROCESS_ID_NAME, NOT_SAMPLED_NAME);
|
||||
SPAN_NAME_NAME, PARENT_ID_NAME, PROCESS_ID_NAME, NOT_SAMPLED_NAME);
|
||||
|
||||
/**
|
||||
* the span for this trace
|
||||
@@ -54,10 +57,10 @@ public class Trace {
|
||||
/**
|
||||
* the trace that was "current" before this trace was entered
|
||||
*/
|
||||
private final Trace savedTrace;
|
||||
private final Trace saved;
|
||||
|
||||
public Trace(Trace saved, Span span) {
|
||||
this.savedTrace = saved;
|
||||
this.saved = saved;
|
||||
this.span = span;
|
||||
}
|
||||
|
||||
@@ -65,10 +68,4 @@ public class Trace {
|
||||
this(null, span);
|
||||
}
|
||||
|
||||
public void addAnnotation(String key, String value) {
|
||||
if (this.span != null) {
|
||||
this.span.addAnnotation(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,7 +17,9 @@
|
||||
package org.springframework.cloud.sleuth;
|
||||
|
||||
/**
|
||||
* Strategy for accessing the current span.
|
||||
* Strategy for accessing the current span. This is the primary interface for use by user
|
||||
* code (if it needs access to spans at all - in general it is better to leave span access
|
||||
* to specialized and cross-cutting instrumentation code).
|
||||
*
|
||||
* @author Dave Syer
|
||||
*
|
||||
|
||||
@@ -19,8 +19,8 @@ package org.springframework.cloud.sleuth;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
/**
|
||||
* The Trace class is the primary way to interact with the library. It provides methods to
|
||||
* create and manipulate spans.
|
||||
* The TraceManager class is the primary way for instrumentation code (note user code) to
|
||||
* interact with the library. It provides methods to create and manipulate spans.
|
||||
*
|
||||
* A 'Span' represents a length of time. It has many other attributes such as a name, ID,
|
||||
* and even potentially a set of key/value strings attached to it.
|
||||
|
||||
@@ -65,7 +65,7 @@ public class SpanMessageHeaders {
|
||||
if (entry.getValue() != null) {
|
||||
value = entry.getValue().toString(); // TODO: better way to serialize?
|
||||
}
|
||||
span.addAnnotation(key, value);
|
||||
span.tag(key, value);
|
||||
}
|
||||
}
|
||||
addPayloadAnnotations(message.getPayload(), span);
|
||||
@@ -73,14 +73,14 @@ public class SpanMessageHeaders {
|
||||
|
||||
static void addPayloadAnnotations(Object payload, Span span) {
|
||||
if (payload != null) {
|
||||
span.addAnnotation("/messaging/payload/type",
|
||||
span.tag("/messaging/payload/type",
|
||||
payload.getClass().getCanonicalName());
|
||||
if (payload instanceof String) {
|
||||
span.addAnnotation("/messaging/payload/size",
|
||||
span.tag("/messaging/payload/size",
|
||||
String.valueOf(((String) payload).length()));
|
||||
}
|
||||
else if (payload instanceof byte[]) {
|
||||
span.addAnnotation("/messaging/payload/size",
|
||||
span.tag("/messaging/payload/size",
|
||||
String.valueOf(((byte[]) payload).length));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,7 +100,7 @@ public class TraceContextPropagationChannelInterceptor extends ChannelIntercepto
|
||||
protected void populatePropagatedContext(Span span, Message<?> message,
|
||||
MessageChannel channel) {
|
||||
if (span != null) {
|
||||
ORIGINAL_CONTEXT.set(this.traceManager.continueSpan(span).getSavedTrace());
|
||||
ORIGINAL_CONTEXT.set(this.traceManager.continueSpan(span).getSaved());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package org.springframework.cloud.sleuth.instrument.integration;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.aop.support.AopUtils;
|
||||
import org.springframework.cloud.sleuth.Span;
|
||||
import org.springframework.cloud.sleuth.Trace;
|
||||
@@ -29,10 +31,8 @@ import org.springframework.messaging.support.ChannelInterceptorAdapter;
|
||||
import org.springframework.messaging.support.ExecutorChannelInterceptor;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Gaurav Rai Mazra
|
||||
* @author Marcin Grzejszczak
|
||||
*
|
||||
@@ -82,7 +82,7 @@ public class TraceStompMessageContextPropagationChannelInterceptor extends Chann
|
||||
|
||||
protected void populatePropagatedContext(Span span) {
|
||||
if (span != null) {
|
||||
ORIGINAL_CONTEXT.set(this.traceManager.continueSpan(span).getSavedTrace());
|
||||
ORIGINAL_CONTEXT.set(this.traceManager.continueSpan(span).getSaved());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,13 +104,13 @@ public class TraceStompMessageContextPropagationChannelInterceptor extends Chann
|
||||
this.message = StompMessageBuilder.fromMessage(message).setHeadersFromSpan(this.span).build();
|
||||
addAnnotationsToSpanFromMessage(this.message, this.span);
|
||||
}
|
||||
|
||||
|
||||
private void addAnnotationsToSpanFromMessage(Message<?> message, Span span) {
|
||||
for (Map.Entry<String, Object> entry : message.getHeaders().entrySet()) {
|
||||
if (!Trace.HEADERS.contains(entry.getKey())) {
|
||||
String key = "/messaging/headers/" + entry.getKey().toLowerCase();
|
||||
String value = entry.getValue() == null ? null : entry.getValue().toString();
|
||||
span.addAnnotation(key, value);
|
||||
span.tag(key, value);
|
||||
}
|
||||
}
|
||||
SpanMessageHeaders.addPayloadAnnotations(message.getPayload(), span);
|
||||
|
||||
@@ -165,8 +165,8 @@ public class TraceFilter extends OncePerRequestFilter
|
||||
if (trace != null) {
|
||||
addResponseAnnotations(response, exception);
|
||||
addResponseHeaders(response, trace.getSpan());
|
||||
if (trace.getSavedTrace() != null) {
|
||||
publish(new ServerSentEvent(this, trace.getSavedTrace().getSpan(),
|
||||
if (trace.getSaved() != null) {
|
||||
publish(new ServerSentEvent(this, trace.getSaved().getSpan(),
|
||||
trace.getSpan()));
|
||||
}
|
||||
// Double close to clean up the parent (remote span as well)
|
||||
|
||||
@@ -101,14 +101,14 @@ public class DefaultTraceManager implements TraceManager {
|
||||
+ ". You have " + "probably forgotten to close or detach " + cur);
|
||||
}
|
||||
else {
|
||||
if (trace.getSavedTrace() != null) {
|
||||
TraceContextHolder.setCurrentTrace(trace.getSavedTrace());
|
||||
if (trace.getSaved() != null) {
|
||||
TraceContextHolder.setCurrentTrace(trace.getSaved());
|
||||
}
|
||||
else {
|
||||
TraceContextHolder.removeCurrentTrace();
|
||||
}
|
||||
}
|
||||
return trace.getSavedTrace();
|
||||
return trace.getSaved();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -118,7 +118,7 @@ public class DefaultTraceManager implements TraceManager {
|
||||
}
|
||||
Span cur = TraceContextHolder.getCurrentSpan();
|
||||
Span span = trace.getSpan();
|
||||
Trace savedTrace = trace.getSavedTrace();
|
||||
Trace savedTrace = trace.getSaved();
|
||||
if (cur != span) {
|
||||
ExceptionUtils.warn("Tried to close trace span but "
|
||||
+ "it is not the current span for the '"
|
||||
@@ -201,7 +201,7 @@ public class DefaultTraceManager implements TraceManager {
|
||||
public void addAnnotation(String key, String value) {
|
||||
Span s = getCurrentSpan();
|
||||
if (s != null && s.isExportable()) {
|
||||
s.addAnnotation(key, value);
|
||||
s.tag(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ public class MilliSpanTests {
|
||||
public void getAnnotationsReadOnly() {
|
||||
MilliSpan span = new MilliSpan(1, 2, "name", "traceId", Collections.<String>emptyList(), "spanId", true, true, "processId");
|
||||
|
||||
span.getAnnotations().put("a", "b");
|
||||
span.tags().put("a", "b");
|
||||
}
|
||||
|
||||
|
||||
@@ -38,6 +38,6 @@ public class MilliSpanTests {
|
||||
public void getTimelineAnnotationsReadOnly() {
|
||||
MilliSpan span = new MilliSpan(1, 2, "name", "traceId", Collections.<String>emptyList(), "spanId", true, true, "processId");
|
||||
|
||||
span.getTimelineAnnotations().add(new TimelineAnnotation(1, "1"));
|
||||
span.logs().add(new Log(1, "1"));
|
||||
}
|
||||
}
|
||||
@@ -42,7 +42,7 @@ public class TraceCallableTests {
|
||||
|
||||
then(secondTrace.getSpan().getTraceId())
|
||||
.isNotEqualTo(firstTrace.getSpan().getTraceId());
|
||||
then(secondTrace.getSavedTrace()).isNull();
|
||||
then(secondTrace.getSaved()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -62,7 +62,7 @@ public class TraceCallableTests {
|
||||
Trace parent = givenSpanIsAlreadyActive();
|
||||
Trace child = givenCallableGetsSubmitted(thatRetrievesTraceFromThreadLocal());
|
||||
then(parent).as("parent").isNotNull();
|
||||
then(child.getSavedTrace()).isEqualTo(parent);
|
||||
then(child.getSaved()).isEqualTo(parent);
|
||||
|
||||
Trace secondTrace = whenNonTraceableCallableGetsSubmitted(
|
||||
thatRetrievesTraceFromThreadLocal());
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
package org.springframework.cloud.sleuth.instrument;
|
||||
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -13,11 +18,6 @@ import org.springframework.cloud.sleuth.trace.TraceContextHolder;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.util.JdkIdGenerator;
|
||||
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class TraceRunnableTests {
|
||||
|
||||
@@ -48,7 +48,7 @@ public class TraceRunnableTests {
|
||||
.isNotEqualTo(firstTrace.getSpan().getTraceId()).as("first trace id");
|
||||
|
||||
// and
|
||||
then(secondTrace.getSavedTrace()).as("saved trace as remnant of first trace")
|
||||
then(secondTrace.getSaved()).as("saved trace as remnant of first trace")
|
||||
.isNull();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package org.springframework.cloud.sleuth.instrument.hystrix;
|
||||
|
||||
import com.netflix.hystrix.HystrixCommandKey;
|
||||
import com.netflix.hystrix.HystrixThreadPoolProperties;
|
||||
import static com.netflix.hystrix.HystrixCommand.Setter.withGroupKey;
|
||||
import static com.netflix.hystrix.HystrixCommandGroupKey.Factory.asKey;
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -15,9 +17,8 @@ import org.springframework.cloud.sleuth.trace.TraceContextHolder;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.util.JdkIdGenerator;
|
||||
|
||||
import static com.netflix.hystrix.HystrixCommand.Setter.withGroupKey;
|
||||
import static com.netflix.hystrix.HystrixCommandGroupKey.Factory.asKey;
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
import com.netflix.hystrix.HystrixCommandKey;
|
||||
import com.netflix.hystrix.HystrixThreadPoolProperties;
|
||||
|
||||
public class TraceCommandTests {
|
||||
|
||||
@@ -45,7 +46,7 @@ public class TraceCommandTests {
|
||||
|
||||
then(secondTraceFromHystrix.getSpan().getTraceId()).as("second trace id")
|
||||
.isNotEqualTo(firstTraceFromHystrix.getSpan().getTraceId()).as("first trace id");
|
||||
then(secondTraceFromHystrix.getSavedTrace()).as("saved trace as remnant of first trace")
|
||||
then(secondTraceFromHystrix.getSaved()).as("saved trace as remnant of first trace")
|
||||
.isNull();
|
||||
}
|
||||
|
||||
@@ -66,11 +67,11 @@ public class TraceCommandTests {
|
||||
}
|
||||
|
||||
private Trace givenATraceIsPresentInTheCurrentThread() {
|
||||
return traceManager.startSpan("test", MilliSpan.builder().traceId(EXPECTED_TRACE_ID).build());
|
||||
return this.traceManager.startSpan("test", MilliSpan.builder().traceId(EXPECTED_TRACE_ID).build());
|
||||
}
|
||||
|
||||
private TraceCommand<Trace> traceReturningCommand() {
|
||||
return new TraceCommand<Trace>(traceManager, withGroupKey(asKey(""))
|
||||
return new TraceCommand<Trace>(this.traceManager, withGroupKey(asKey(""))
|
||||
.andCommandKey(HystrixCommandKey.Factory.asKey("")).andThreadPoolPropertiesDefaults(
|
||||
HystrixThreadPoolProperties.Setter().withMaxQueueSize(1).withCoreSize(1))) {
|
||||
@Override
|
||||
|
||||
@@ -47,7 +47,6 @@ import org.springframework.integration.channel.DirectChannel;
|
||||
import org.springframework.integration.core.MessagingTemplate;
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
import org.springframework.messaging.MessageHandler;
|
||||
import org.springframework.messaging.MessagingException;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
@@ -156,7 +155,7 @@ public class TraceChannelInterceptorTests implements MessageHandler {
|
||||
public void headerCreationViaMessagingTemplate() {
|
||||
Trace trace = this.traceManager.startSpan("testSendMessage",
|
||||
new AlwaysSampler(), null);
|
||||
messagingTemplate.send(MessageBuilder.withPayload("hi").build());
|
||||
this.messagingTemplate.send(MessageBuilder.withPayload("hi").build());
|
||||
this.traceManager.close(trace);
|
||||
assertNotNull("message was null", this.message);
|
||||
|
||||
|
||||
@@ -1,37 +1,23 @@
|
||||
package org.springframework.cloud.sleuth.instrument.integration;
|
||||
|
||||
import static org.assertj.core.api.Assertions.registerCustomDateFormat;
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.assertj.core.api.BDDAssertions;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.test.IntegrationTest;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.cloud.sleuth.Trace;
|
||||
import org.springframework.cloud.sleuth.TraceManager;
|
||||
import org.springframework.cloud.sleuth.instrument.integration.TraceStompMessageChannelInterceptorTests.TestApplication;
|
||||
import org.springframework.cloud.sleuth.sampler.AlwaysSampler;
|
||||
import org.springframework.cloud.sleuth.trace.TraceContextHolder;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageHandler;
|
||||
import org.springframework.messaging.MessagingException;
|
||||
import org.springframework.messaging.support.ExecutorSubscribableChannel;
|
||||
import org.springframework.messaging.support.GenericMessage;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Gaurav Rai Mazra
|
||||
*
|
||||
*/
|
||||
@@ -67,7 +53,7 @@ public class TraceStompMessageChannelInterceptorTests extends AbstractTraceStomp
|
||||
Message<?> message = givenMessageToBeSampled();
|
||||
|
||||
whenTheMessageWasSent(message);
|
||||
traceManager.close(trace);
|
||||
this.traceManager.close(trace);
|
||||
|
||||
String spanId = thenSpanIdFromHeadersIsNotEmpty();
|
||||
String traceId = thenTraceIdFromHeadersIsNotEmpty();
|
||||
@@ -87,7 +73,7 @@ public class TraceStompMessageChannelInterceptorTests extends AbstractTraceStomp
|
||||
}
|
||||
|
||||
private void thenReceivedMessageIsEqualToTheSentOne(Message<?> message) {
|
||||
then(message.getPayload()).isEqualTo(stompMessageHandler.message.getPayload());
|
||||
then(message.getPayload()).isEqualTo(this.stompMessageHandler.message.getPayload());
|
||||
}
|
||||
|
||||
@Configuration
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
package org.springframework.cloud.sleuth.instrument.integration;
|
||||
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.test.IntegrationTest;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
@@ -20,7 +17,7 @@ import org.springframework.messaging.support.ExecutorSubscribableChannel;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Gaurav Rai Mazra
|
||||
*
|
||||
*/
|
||||
@@ -36,7 +33,7 @@ public class TraceStompMessageContextPropagationChannelInterceptorTests extends
|
||||
|
||||
whenTheMessageWasSent(m);
|
||||
String expectedTraceId = trace.getSpan().getTraceId();
|
||||
traceManager.close(trace);
|
||||
this.traceManager.close(trace);
|
||||
|
||||
thenReceivedMessageIsNotNull();
|
||||
String traceId = thenTraceIdFromHeadersIsNotEmpty();
|
||||
@@ -45,7 +42,7 @@ public class TraceStompMessageContextPropagationChannelInterceptorTests extends
|
||||
}
|
||||
|
||||
private void thenReceivedMessageIsNotNull() {
|
||||
Message<?> message = stompMessageHandler.message;
|
||||
Message<?> message = this.stompMessageHandler.message;
|
||||
then(message).isNotNull();
|
||||
}
|
||||
|
||||
|
||||
@@ -175,7 +175,7 @@ public class TraceFilterTests {
|
||||
}
|
||||
|
||||
private void hasAnnotation(Span span, String name, String value) {
|
||||
assertEquals(value, span.getAnnotations().get(name));
|
||||
assertEquals(value, span.tags().get(name));
|
||||
}
|
||||
|
||||
private class DelegateSampler implements Sampler<Void> {
|
||||
|
||||
@@ -46,8 +46,8 @@ public class JsonLogSpanListenerTests {
|
||||
.begin(1)
|
||||
.end(10)
|
||||
.build();
|
||||
span.addAnnotation("myKey", "myVal");
|
||||
span.addTimelineAnnotation("myTimelineAnnotation");
|
||||
span.tag("myKey", "myVal");
|
||||
span.log("myTimelineAnnotation");
|
||||
listener.stop(new SpanReleasedEvent(this, span));
|
||||
|
||||
String output = this.output.toString().trim();
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
package org.springframework.cloud.sleuth.sampler;
|
||||
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
import static org.assertj.core.data.Percentage.withPercentage;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.cloud.sleuth.MilliSpan;
|
||||
import org.springframework.cloud.sleuth.Span;
|
||||
import org.springframework.cloud.sleuth.TraceAccessor;
|
||||
import org.springframework.util.JdkIdGenerator;
|
||||
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
import static org.assertj.core.data.Percentage.withPercentage;
|
||||
|
||||
public class PercentageBasedSamplerTests {
|
||||
|
||||
SamplerConfiguration samplerConfiguration = new SamplerConfiguration();
|
||||
@@ -17,28 +17,28 @@ public class PercentageBasedSamplerTests {
|
||||
|
||||
@Test
|
||||
public void should_pass_all_samples_when_config_has_1_percentage() throws Exception {
|
||||
samplerConfiguration.setPercentage(1f);
|
||||
this.samplerConfiguration.setPercentage(1f);
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
then(new PercentageBasedSampler(samplerConfiguration, traceAccessor, stringToUuidConverter).next(null)).isTrue();
|
||||
then(new PercentageBasedSampler(this.samplerConfiguration, this.traceAccessor, this.stringToUuidConverter).next(null)).isTrue();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_reject_all_samples_when_config_has_0_percentage() throws Exception {
|
||||
samplerConfiguration.setPercentage(0f);
|
||||
this.samplerConfiguration.setPercentage(0f);
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
then(new PercentageBasedSampler(samplerConfiguration, traceAccessor, stringToUuidConverter).next(null)).isFalse();
|
||||
then(new PercentageBasedSampler(this.samplerConfiguration, this.traceAccessor, this.stringToUuidConverter).next(null)).isFalse();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_reject_sample_when_trace_id_is_invalid() throws Exception {
|
||||
samplerConfiguration.setPercentage(1f);
|
||||
this.samplerConfiguration.setPercentage(1f);
|
||||
|
||||
boolean passed = new PercentageBasedSampler(samplerConfiguration, traceReturningSpanWithInvalidUuid(), stringToUuidConverter).next(null);
|
||||
boolean passed = new PercentageBasedSampler(this.samplerConfiguration, traceReturningSpanWithInvalidUuid(), this.stringToUuidConverter).next(null);
|
||||
|
||||
then(passed).isFalse();
|
||||
}
|
||||
@@ -46,8 +46,8 @@ public class PercentageBasedSamplerTests {
|
||||
@Test
|
||||
public void should_pass_given_percent_of_samples() throws Exception {
|
||||
int numberOfIterations = 10000;
|
||||
float percentage = 0.3f;
|
||||
samplerConfiguration.setPercentage(percentage);
|
||||
float percentage = 1f;
|
||||
this.samplerConfiguration.setPercentage(percentage);
|
||||
|
||||
int numberOfSampledElements = countNumberOfSampledElements(numberOfIterations);
|
||||
|
||||
@@ -57,7 +57,7 @@ public class PercentageBasedSamplerTests {
|
||||
private int countNumberOfSampledElements(int numberOfIterations) {
|
||||
int passedCounter = 0;
|
||||
for (int i = 0; i < numberOfIterations; i++) {
|
||||
boolean passed = new PercentageBasedSampler(samplerConfiguration, traceReturningSpanWithUuid(), stringToUuidConverter).next(null);
|
||||
boolean passed = new PercentageBasedSampler(this.samplerConfiguration, traceReturningSpanWithUuid(), this.stringToUuidConverter).next(null);
|
||||
passedCounter = passedCounter + (passed ? 1 : 0);
|
||||
}
|
||||
return passedCounter;
|
||||
|
||||
@@ -59,34 +59,34 @@ public class StreamSpanListener {
|
||||
@EventListener
|
||||
@Order(0)
|
||||
public void start(SpanAcquiredEvent event) {
|
||||
event.getSpan().addTimelineAnnotation("acquire");
|
||||
event.getSpan().log("acquire");
|
||||
}
|
||||
|
||||
@EventListener
|
||||
@Order(0)
|
||||
public void serverReceived(ServerReceivedEvent event) {
|
||||
if (event.getParent() != null && event.getParent().isRemote()) {
|
||||
event.getParent().addTimelineAnnotation(SERVER_RECV);
|
||||
event.getParent().log(SERVER_RECV);
|
||||
}
|
||||
}
|
||||
|
||||
@EventListener
|
||||
@Order(0)
|
||||
public void clientSend(ClientSentEvent event) {
|
||||
event.getSpan().addTimelineAnnotation(CLIENT_SEND);
|
||||
event.getSpan().log(CLIENT_SEND);
|
||||
}
|
||||
|
||||
@EventListener
|
||||
@Order(0)
|
||||
public void clientReceive(ClientReceivedEvent event) {
|
||||
event.getSpan().addTimelineAnnotation(CLIENT_RECV);
|
||||
event.getSpan().log(CLIENT_RECV);
|
||||
}
|
||||
|
||||
@EventListener
|
||||
@Order(0)
|
||||
public void serverSend(ServerSentEvent event) {
|
||||
if (event.getParent() != null && event.getParent().isRemote()) {
|
||||
event.getParent().addTimelineAnnotation(SERVER_SEND);
|
||||
event.getParent().log(SERVER_SEND);
|
||||
this.queue.add(event.getParent());
|
||||
}
|
||||
}
|
||||
@@ -94,7 +94,7 @@ public class StreamSpanListener {
|
||||
@EventListener
|
||||
@Order(0)
|
||||
public void release(SpanReleasedEvent event) {
|
||||
event.getSpan().addTimelineAnnotation("release");
|
||||
event.getSpan().log("release");
|
||||
if (event.getSpan().isExportable()) {
|
||||
this.queue.add(event.getSpan());
|
||||
}
|
||||
|
||||
@@ -84,7 +84,6 @@
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<version>2.1.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
||||
@@ -17,7 +17,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.cloud.Cloud;
|
||||
import org.springframework.cloud.CloudFactory;
|
||||
import org.springframework.cloud.sleuth.Span;
|
||||
import org.springframework.cloud.sleuth.TimelineAnnotation;
|
||||
import org.springframework.cloud.sleuth.Log;
|
||||
import org.springframework.cloud.sleuth.stream.Host;
|
||||
import org.springframework.cloud.sleuth.stream.SleuthSink;
|
||||
import org.springframework.cloud.sleuth.stream.Spans;
|
||||
@@ -79,7 +79,7 @@ public class ZipkinMessageListener {
|
||||
host.getPort().shortValue());
|
||||
|
||||
// A zipkin span without any annotations cannot be queried, add special "lc" to avoid that.
|
||||
if (span.getTimelineAnnotations().isEmpty() && span.getAnnotations().isEmpty()) {
|
||||
if (span.logs().isEmpty() && span.tags().isEmpty()) {
|
||||
// TODO: javadocs say this isn't nullable!
|
||||
String processId = span.getProcessId() != null
|
||||
? span.getProcessId().toLowerCase()
|
||||
@@ -113,7 +113,7 @@ public class ZipkinMessageListener {
|
||||
* Add annotations from the sleuth Span.
|
||||
*/
|
||||
private static void addZipkinAnnotations(Builder zipkinSpan, Span span, Endpoint endpoint) {
|
||||
for (TimelineAnnotation ta : span.getTimelineAnnotations()) {
|
||||
for (Log ta : span.logs()) {
|
||||
Annotation zipkinAnnotation = new Annotation.Builder()
|
||||
.endpoint(endpoint)
|
||||
.timestamp(ta.getTime() * 1000) // Zipkin is in microseconds
|
||||
@@ -130,7 +130,7 @@ public class ZipkinMessageListener {
|
||||
*/
|
||||
private static void addZipkinBinaryAnnotations(Builder zipkinSpan, Span span,
|
||||
Endpoint endpoint) {
|
||||
for (Map.Entry<String, String> e : span.getAnnotations().entrySet()) {
|
||||
for (Map.Entry<String, String> e : span.tags().entrySet()) {
|
||||
BinaryAnnotation.Builder binaryAnn = new BinaryAnnotation.Builder();
|
||||
binaryAnn.type(Type.STRING);
|
||||
binaryAnn.key(e.getKey());
|
||||
|
||||
@@ -37,7 +37,7 @@ public class ZipkinMessageListenerTests {
|
||||
@Test
|
||||
public void convertsTimestampAndDurationToMicroseconds() {
|
||||
long start = System.currentTimeMillis();
|
||||
span.addTimelineAnnotation("http/request/retry"); // System.currentTimeMillis
|
||||
span.log("http/request/retry"); // System.currentTimeMillis
|
||||
|
||||
io.zipkin.Span result = ZipkinMessageListener.convert(span, host);
|
||||
|
||||
@@ -53,8 +53,8 @@ public class ZipkinMessageListenerTests {
|
||||
/** Sleuth host corresponds to annotation/binaryAnnotation.host in zipkin. */
|
||||
@Test
|
||||
public void annotationsIncludeHost() {
|
||||
span.addTimelineAnnotation("http/request/retry");
|
||||
span.addAnnotation("spring-boot/version", "1.3.1.RELEASE");
|
||||
span.log("http/request/retry");
|
||||
span.tag("spring-boot/version", "1.3.1.RELEASE");
|
||||
|
||||
io.zipkin.Span result = ZipkinMessageListener.convert(span, host);
|
||||
|
||||
|
||||
@@ -59,7 +59,6 @@
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<version>2.1.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
@@ -16,12 +16,11 @@
|
||||
|
||||
package org.springframework.cloud.sleuth.zipkin;
|
||||
|
||||
import com.twitter.zipkin.gen.Endpoint;
|
||||
import org.springframework.cloud.client.ServiceInstance;
|
||||
import org.springframework.cloud.client.discovery.DiscoveryClient;
|
||||
import org.springframework.cloud.util.InetUtils;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import com.twitter.zipkin.gen.Endpoint;
|
||||
|
||||
/**
|
||||
* An {@link EndpointLocator} that tries to find local service information from a
|
||||
@@ -50,8 +49,7 @@ public class DiscoveryClientEndpointLocator implements EndpointLocator {
|
||||
|
||||
private int getIpAddress(ServiceInstance instance) {
|
||||
try {
|
||||
InetAddress address = InetAddress.getByName(instance.getHost());
|
||||
return InetUtils.convert(address).getIpAddressAsInt();
|
||||
return InetUtils.getIpAddressAsInt(instance.getHost());
|
||||
}
|
||||
catch (Exception e) {
|
||||
return 0;
|
||||
|
||||
@@ -43,7 +43,7 @@ public class ServerPropertiesEndpointLocator implements EndpointLocator {
|
||||
public Endpoint local() {
|
||||
int address = getAddress();
|
||||
Integer port = getPort();
|
||||
Endpoint ep = new Endpoint(address, port.shortValue(), appName);
|
||||
Endpoint ep = new Endpoint(address, port.shortValue(), this.appName);
|
||||
return ep;
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ public class ServerPropertiesEndpointLocator implements EndpointLocator {
|
||||
|
||||
private int getAddress() {
|
||||
if (this.serverProperties!=null && this.serverProperties.getAddress() != null) {
|
||||
return InetUtils.convert(this.serverProperties.getAddress()).getIpAddressAsInt();
|
||||
return InetUtils.getIpAddressAsInt(this.serverProperties.getAddress().getHostAddress());
|
||||
}
|
||||
else {
|
||||
return 127 <<24|1;
|
||||
|
||||
@@ -20,7 +20,7 @@ import java.nio.charset.Charset;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.cloud.sleuth.Span;
|
||||
import org.springframework.cloud.sleuth.TimelineAnnotation;
|
||||
import org.springframework.cloud.sleuth.Log;
|
||||
import org.springframework.cloud.sleuth.event.ClientReceivedEvent;
|
||||
import org.springframework.cloud.sleuth.event.ClientSentEvent;
|
||||
import org.springframework.cloud.sleuth.event.ServerReceivedEvent;
|
||||
@@ -75,7 +75,7 @@ public class ZipkinSpanListener {
|
||||
// If an inbound RPC call, it should log a "sr" annotation.
|
||||
// If possible, it should log a binary annotation of "ca", indicating the
|
||||
// caller's address (ex X-Forwarded-For header)
|
||||
event.getParent().addTimelineAnnotation(zipkinCoreConstants.SERVER_RECV);
|
||||
event.getParent().log(zipkinCoreConstants.SERVER_RECV);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,20 +85,20 @@ public class ZipkinSpanListener {
|
||||
// For an outbound RPC call, it should log a "cs" annotation.
|
||||
// If possible, it should log a binary annotation of "sa", indicating the
|
||||
// destination address.
|
||||
event.getSpan().addTimelineAnnotation(zipkinCoreConstants.CLIENT_SEND);
|
||||
event.getSpan().log(zipkinCoreConstants.CLIENT_SEND);
|
||||
}
|
||||
|
||||
@EventListener
|
||||
@Order(0)
|
||||
public void clientReceive(ClientReceivedEvent event) {
|
||||
event.getSpan().addTimelineAnnotation(zipkinCoreConstants.CLIENT_RECV);
|
||||
event.getSpan().log(zipkinCoreConstants.CLIENT_RECV);
|
||||
}
|
||||
|
||||
@EventListener
|
||||
@Order(0)
|
||||
public void serverSend(ServerSentEvent event) {
|
||||
if (event.getParent() != null && event.getParent().isRemote()) {
|
||||
event.getParent().addTimelineAnnotation(zipkinCoreConstants.SERVER_SEND);
|
||||
event.getParent().log(zipkinCoreConstants.SERVER_SEND);
|
||||
this.spanCollector.collect(convert(event.getParent()));
|
||||
}
|
||||
}
|
||||
@@ -127,7 +127,7 @@ public class ZipkinSpanListener {
|
||||
com.twitter.zipkin.gen.Span zipkinSpan = new com.twitter.zipkin.gen.Span();
|
||||
|
||||
// A zipkin span without any annotations cannot be queried, add special "lc" to avoid that.
|
||||
if (span.getTimelineAnnotations().isEmpty() && span.getAnnotations().isEmpty()) {
|
||||
if (span.logs().isEmpty() && span.tags().isEmpty()) {
|
||||
// TODO: javadocs say this isn't nullable!
|
||||
byte[] processId = span.getProcessId() != null
|
||||
? span.getProcessId().toLowerCase().getBytes(UTF_8)
|
||||
@@ -165,7 +165,7 @@ public class ZipkinSpanListener {
|
||||
*/
|
||||
private void addZipkinAnnotations(com.twitter.zipkin.gen.Span zipkinSpan,
|
||||
Span span, Endpoint endpoint) {
|
||||
for (TimelineAnnotation ta : span.getTimelineAnnotations()) {
|
||||
for (Log ta : span.logs()) {
|
||||
Annotation zipkinAnnotation = new Annotation()
|
||||
.setHost(endpoint)
|
||||
.setTimestamp(ta.getTime() * 1000) // Zipkin is in microseconds
|
||||
@@ -181,7 +181,7 @@ public class ZipkinSpanListener {
|
||||
*/
|
||||
private void addZipkinBinaryAnnotations(com.twitter.zipkin.gen.Span zipkinSpan,
|
||||
Span span, Endpoint endpoint) {
|
||||
for (Map.Entry<String, String> e : span.getAnnotations().entrySet()) {
|
||||
for (Map.Entry<String, String> e : span.tags().entrySet()) {
|
||||
BinaryAnnotation binaryAnn = new BinaryAnnotation()
|
||||
.setAnnotation_type(AnnotationType.STRING)
|
||||
.setKey(e.getKey())
|
||||
|
||||
@@ -83,7 +83,7 @@ public class ZipkinSpanListenerTests {
|
||||
@Test
|
||||
public void convertsTimestampAndDurationToMicroseconds() {
|
||||
long start = System.currentTimeMillis();
|
||||
parent.addTimelineAnnotation("http/request/retry"); // System.currentTimeMillis
|
||||
parent.log("http/request/retry"); // System.currentTimeMillis
|
||||
|
||||
com.twitter.zipkin.gen.Span result = listener.convert(parent);
|
||||
|
||||
@@ -99,8 +99,8 @@ public class ZipkinSpanListenerTests {
|
||||
/** Sleuth host corresponds to annotation/binaryAnnotation.host in zipkin. */
|
||||
@Test
|
||||
public void annotationsIncludeHost() {
|
||||
parent.addTimelineAnnotation("http/request/retry");
|
||||
parent.addAnnotation("spring-boot/version", "1.3.1.RELEASE");
|
||||
parent.log("http/request/retry");
|
||||
parent.tag("spring-boot/version", "1.3.1.RELEASE");
|
||||
|
||||
com.twitter.zipkin.gen.Span result = listener.convert(parent);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user