Simplified Tracer API
This commit is contained in:
@@ -73,7 +73,7 @@ The span is also removed from the current thread.
|
||||
- <<continuing-spans, continue>> - a new instance of span will be created whereas it will be a copy of the
|
||||
one that it continues.
|
||||
- <<continuing-spans, detach>> - the span doesn't get stopped or closed. It only gets removed from the current thread.
|
||||
- <<joining-spans, join>> - you can create a new span and set an explicit parent to it
|
||||
- <<creating-spans-with-explicit-parent, create with explicit parent>> - you can create a new span and set an explicit parent to it
|
||||
|
||||
=== Creating and closing spans [[creating-and-closing-spans]]
|
||||
|
||||
@@ -117,18 +117,18 @@ IMPORTANT: Always clean after you create a span! Don't forget to detach a span i
|
||||
Then the spans in the threads Y, Z should be detached at the end of their work. When the results are collected
|
||||
the span in thread X should be closed.
|
||||
|
||||
=== Joining spans [[joining-spans]]
|
||||
=== Creating spans with an explicit parent [[creating-spans-with-explicit-parent]]
|
||||
|
||||
There is a possibility that you want to start a new span and provide an explicit parent of that span.
|
||||
Let's assume that the parent of a span is in one thread and you want to start a new span in another thread. The
|
||||
`joinTrace` method of the `Tracer` interface is the method you are looking for.
|
||||
`startSpan` method of the `Tracer` interface is the method you are looking for.
|
||||
|
||||
[source,java]
|
||||
----
|
||||
include::../../../../spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/documentation/SpringCloudSleuthDocTests.java[tags=manual_span_joining,indent=0]
|
||||
----
|
||||
|
||||
IMPORTANT: After having joined the span remember to close it. Otherwise you will see a lot of warnings in your logs
|
||||
IMPORTANT: After having created such a span remember to close it. Otherwise you will see a lot of warnings in your logs
|
||||
related to the fact that you have a span present in the current thread other than the one you're trying to close.
|
||||
What's worse your spans won't get closed properly thus will not get collected to Zipkin.
|
||||
|
||||
|
||||
@@ -59,7 +59,7 @@ public class TraceCallable<V> implements Callable<V> {
|
||||
}
|
||||
|
||||
protected Span startSpan() {
|
||||
return this.tracer.joinTrace(getSpanName(), this.parent);
|
||||
return this.tracer.createSpan(getSpanName(), this.parent);
|
||||
}
|
||||
|
||||
protected String getSpanName() {
|
||||
|
||||
@@ -63,7 +63,7 @@ public class TraceRunnable implements Runnable {
|
||||
}
|
||||
|
||||
protected Span startSpan() {
|
||||
return this.tracer.joinTrace(getSpanName(), this.parent);
|
||||
return this.tracer.createSpan(getSpanName(), this.parent);
|
||||
}
|
||||
|
||||
protected String getSpanName() {
|
||||
|
||||
@@ -36,9 +36,9 @@ import java.util.concurrent.Callable;
|
||||
*
|
||||
* Most crucial methods in terms of span lifecycle are:
|
||||
* <ul>
|
||||
* <li>The {@linkplain Tracer#startTrace(String) startTrace} method in this class
|
||||
* <li>The {@linkplain Tracer#createSpan(String) createSpan} method in this class
|
||||
* starts a new span.</li>
|
||||
* <li>The {@linkplain Tracer#joinTrace(String, Span) joinTrace} method creates a new span
|
||||
* <li>The {@linkplain Tracer#createSpan(String, Span) createSpan} method creates a new span
|
||||
* which has this thread's currentSpan as one of its parents</li>
|
||||
* <li>The {@linkplain Tracer#continueSpan(Span) continueSpan} method creates a
|
||||
* new instance of span that logically is a continuation of the provided span.</li>
|
||||
@@ -63,7 +63,7 @@ public interface Tracer extends SpanAccessor {
|
||||
*
|
||||
* @param name The name field for the new span to create.
|
||||
*/
|
||||
Span startTrace(String name);
|
||||
Span createSpan(String name);
|
||||
|
||||
/**
|
||||
* Creates a new Span with a specific parent. The parent might be in another
|
||||
@@ -75,7 +75,7 @@ public interface Tracer extends SpanAccessor {
|
||||
*
|
||||
* @param name The name field for the new span to create.
|
||||
*/
|
||||
Span joinTrace(String name, Span parent);
|
||||
Span createSpan(String name, Span parent);
|
||||
|
||||
/**
|
||||
* Start a new span if the sampler allows it or if we are already tracing in this
|
||||
@@ -84,7 +84,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(String name, Sampler sampler);
|
||||
Span createSpan(String name, Sampler sampler);
|
||||
|
||||
/**
|
||||
* Contributes to a span started in another thread. The returned span shares
|
||||
|
||||
@@ -61,7 +61,7 @@ public class LocalComponentTraceCallable<V> extends TraceCallable<V> {
|
||||
|
||||
@Override
|
||||
protected Span startSpan() {
|
||||
Span span = getTracer().joinTrace(getSpanName(), getParent());
|
||||
Span span = getTracer().createSpan(getSpanName(), getParent());
|
||||
getTracer().addTag(Span.SPAN_LOCAL_COMPONENT_TAG_NAME, ASYNC_COMPONENT);
|
||||
getTracer().addTag(this.traceKeys.getAsync().getPrefix() +
|
||||
this.traceKeys.getAsync().getThreadNameKey(), Thread.currentThread().getName());
|
||||
|
||||
@@ -59,7 +59,7 @@ public class LocalComponentTraceRunnable extends TraceRunnable {
|
||||
|
||||
@Override
|
||||
protected Span startSpan() {
|
||||
Span span = getTracer().joinTrace(getSpanName(), getParent());
|
||||
Span span = getTracer().createSpan(getSpanName(), getParent());
|
||||
getTracer().addTag(Span.SPAN_LOCAL_COMPONENT_TAG_NAME, ASYNC_COMPONENT);
|
||||
getTracer().addTag(this.traceKeys.getAsync().getPrefix() +
|
||||
this.traceKeys.getAsync().getThreadNameKey(), Thread.currentThread().getName());
|
||||
|
||||
@@ -47,7 +47,7 @@ public class TraceAsyncAspect {
|
||||
|
||||
@Around("execution (@org.springframework.scheduling.annotation.Async * *.*(..))")
|
||||
public Object traceBackgroundThread(final ProceedingJoinPoint pjp) throws Throwable {
|
||||
Span span = this.tracer.startTrace(pjp.getSignature().getName());
|
||||
Span span = this.tracer.createSpan(pjp.getSignature().getName());
|
||||
this.tracer.addTag(Span.SPAN_LOCAL_COMPONENT_TAG_NAME, ASYNC_COMPONENT);
|
||||
this.tracer.addTag(this.traceKeys.getAsync().getPrefix() +
|
||||
this.traceKeys.getAsync().getClassNameKey(), pjp.getTarget().getClass().getSimpleName());
|
||||
|
||||
@@ -77,7 +77,7 @@ public class SleuthHystrixConcurrencyStrategy extends HystrixConcurrencyStrategy
|
||||
span = this.tracer.continueSpan(span);
|
||||
}
|
||||
else {
|
||||
span = this.tracer.startTrace(HYSTRIX_COMPONENT);
|
||||
span = this.tracer.createSpan(HYSTRIX_COMPONENT);
|
||||
this.tracer.addTag(Span.SPAN_LOCAL_COMPONENT_TAG_NAME, HYSTRIX_COMPONENT);
|
||||
this.tracer.addTag(this.traceKeys.getAsync().getPrefix() +
|
||||
this.traceKeys.getAsync().getThreadNameKey(), Thread.currentThread().getName());
|
||||
|
||||
@@ -50,7 +50,7 @@ public abstract class TraceCommand<R> extends HystrixCommand<R> {
|
||||
@Override
|
||||
protected R run() throws Exception {
|
||||
String commandKeyName = getCommandKey().name();
|
||||
Span span = this.tracer.joinTrace(commandKeyName, this.parentSpan);
|
||||
Span span = this.tracer.createSpan(commandKeyName, this.parentSpan);
|
||||
this.tracer.addTag(Span.SPAN_LOCAL_COMPONENT_TAG_NAME, HYSTRIX_COMPONENT);
|
||||
this.tracer.addTag(this.traceKeys.getHystrix().getPrefix() +
|
||||
this.traceKeys.getHystrix().getCommandKey(), commandKeyName);
|
||||
|
||||
@@ -54,12 +54,12 @@ public class TraceChannelInterceptor extends AbstractTraceChannelInterceptor {
|
||||
|
||||
private Span startSpan(Span span, String name, Message<?> message) {
|
||||
if (span != null) {
|
||||
return getTracer().joinTrace(name, span);
|
||||
return getTracer().createSpan(name, span);
|
||||
}
|
||||
if (message.getHeaders().containsKey(Span.NOT_SAMPLED_NAME)) {
|
||||
return getTracer().startTrace(name, NeverSampler.INSTANCE);
|
||||
return getTracer().createSpan(name, NeverSampler.INSTANCE);
|
||||
}
|
||||
return getTracer().startTrace(name);
|
||||
return getTracer().createSpan(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -51,7 +51,7 @@ public class TraceSchedulingAspect {
|
||||
@Around("execution (@org.springframework.scheduling.annotation.Scheduled * *.*(..))")
|
||||
public Object traceBackgroundThread(final ProceedingJoinPoint pjp) throws Throwable {
|
||||
String spanName = pjp.getTarget().getClass().getSimpleName();
|
||||
Span span = this.tracer.startTrace(spanName);
|
||||
Span span = this.tracer.createSpan(spanName);
|
||||
this.tracer.addTag(Span.SPAN_LOCAL_COMPONENT_TAG_NAME, SCHEDULED_COMPONENT);
|
||||
try {
|
||||
return pjp.proceed();
|
||||
|
||||
@@ -151,18 +151,18 @@ public class TraceFilter extends OncePerRequestFilter
|
||||
span.remote(true);
|
||||
|
||||
Span parent = span.build();
|
||||
spanFromRequest = this.tracer.joinTrace(name, parent);
|
||||
spanFromRequest = this.tracer.createSpan(name, parent);
|
||||
publish(new ServerReceivedEvent(this, parent, spanFromRequest));
|
||||
request.setAttribute(TRACE_REQUEST_ATTR, spanFromRequest);
|
||||
|
||||
}
|
||||
else {
|
||||
if (skip) {
|
||||
spanFromRequest = this.tracer.startTrace(name,
|
||||
spanFromRequest = this.tracer.createSpan(name,
|
||||
NeverSampler.INSTANCE);
|
||||
}
|
||||
else {
|
||||
spanFromRequest = this.tracer.startTrace(name);
|
||||
spanFromRequest = this.tracer.createSpan(name);
|
||||
}
|
||||
request.setAttribute(TRACE_REQUEST_ATTR, spanFromRequest);
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ abstract class AbstractTraceHttpRequestInterceptor
|
||||
protected void publishStartEvent(HttpRequest request) {
|
||||
URI uri = request.getURI();
|
||||
String spanName = uriScheme(uri) + ":" + uri.getPath();
|
||||
Span newSpan = this.tracer.startTrace(spanName);
|
||||
Span newSpan = this.tracer.createSpan(spanName);
|
||||
enrichWithTraceHeaders(request, newSpan);
|
||||
publish(new ClientSentEvent(this, newSpan));
|
||||
}
|
||||
|
||||
@@ -126,7 +126,7 @@ public class TraceFeignClientAutoConfiguration {
|
||||
public void apply(RequestTemplate template) {
|
||||
URI uri = URI.create(template.url());
|
||||
String spanName = uriScheme(uri) + ":" + uri.getPath();
|
||||
Span span = TraceFeignClientAutoConfiguration.this.tracer.startTrace(spanName);
|
||||
Span span = TraceFeignClientAutoConfiguration.this.tracer.createSpan(spanName);
|
||||
if (span == null) {
|
||||
setHeader(template, Span.NOT_SAMPLED_NAME, "true");
|
||||
return;
|
||||
|
||||
@@ -57,20 +57,20 @@ public class DefaultTracer implements Tracer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Span joinTrace(String name, Span parent) {
|
||||
public Span createSpan(String name, Span parent) {
|
||||
if (parent == null) {
|
||||
return startTrace(name);
|
||||
return createSpan(name);
|
||||
}
|
||||
return continueSpan(createChild(parent, name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Span startTrace(String name) {
|
||||
return this.startTrace(name, this.defaultSampler);
|
||||
public Span createSpan(String name) {
|
||||
return this.createSpan(name, this.defaultSampler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Span startTrace(String name, Sampler sampler) {
|
||||
public Span createSpan(String name, Sampler sampler) {
|
||||
Span span;
|
||||
if (isTracing()) {
|
||||
span = createChild(getCurrentSpan(), name);
|
||||
|
||||
@@ -84,7 +84,7 @@ public class SpringCloudSleuthDocTests {
|
||||
future.get();
|
||||
// end::span_name_annotated_runnable_execution[]
|
||||
|
||||
BDDMockito.then(tracer).should().joinTrace(BDDMockito.eq("calculateTax"), BDDMockito.any(Span.class));
|
||||
BDDMockito.then(tracer).should().createSpan(BDDMockito.eq("calculateTax"), BDDMockito.any(Span.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -109,7 +109,7 @@ public class SpringCloudSleuthDocTests {
|
||||
future.get();
|
||||
// end::span_name_to_string_runnable_execution[]
|
||||
|
||||
BDDMockito.then(tracer).should().joinTrace(BDDMockito.eq("calculateTax"), BDDMockito.any(Span.class));
|
||||
BDDMockito.then(tracer).should().createSpan(BDDMockito.eq("calculateTax"), BDDMockito.any(Span.class));
|
||||
executorService.shutdown();
|
||||
}
|
||||
|
||||
@@ -123,7 +123,7 @@ public class SpringCloudSleuthDocTests {
|
||||
// tag::manual_span_creation[]
|
||||
// Start a span. If there was a span present in this thread it will become
|
||||
// the `newSpan`'s parent.
|
||||
Span newSpan = this.tracer.startTrace("calculateTax");
|
||||
Span newSpan = this.tracer.createSpan("calculateTax");
|
||||
try {
|
||||
// ...
|
||||
// You can tag a span
|
||||
@@ -146,7 +146,7 @@ public class SpringCloudSleuthDocTests {
|
||||
public void should_continue_a_span_with_tracer() throws Exception {
|
||||
ExecutorService executorService = Executors.newSingleThreadExecutor();
|
||||
String taxValue = "10";
|
||||
Span initialSpan = this.tracer.startTrace("calculateTax");
|
||||
Span initialSpan = this.tracer.createSpan("calculateTax");
|
||||
assertThat(initialSpan.tags()).doesNotContainKeys("taxValue");
|
||||
assertThat(initialSpan.logs()).extracting("event").doesNotContain("taxCalculated");
|
||||
|
||||
@@ -183,7 +183,7 @@ public class SpringCloudSleuthDocTests {
|
||||
public void should_join_a_span_with_tracer() throws Exception {
|
||||
ExecutorService executorService = Executors.newSingleThreadExecutor();
|
||||
String commissionValue = "10";
|
||||
Span initialSpan = this.tracer.startTrace("calculateTax");
|
||||
Span initialSpan = this.tracer.createSpan("calculateTax");
|
||||
assertThat(initialSpan.tags()).doesNotContainKeys("commissionValue");
|
||||
assertThat(initialSpan.logs()).extracting("event").doesNotContain("commissionCalculated");
|
||||
|
||||
@@ -192,7 +192,7 @@ public class SpringCloudSleuthDocTests {
|
||||
// let's assume that we're in a thread Y and we've received
|
||||
// the `initialSpan` from thread X. `initialSpan` will be the parent
|
||||
// of the `joinedSpan`
|
||||
Span joinedSpan = this.tracer.joinTrace("calculateCommission", initialSpan);
|
||||
Span joinedSpan = this.tracer.createSpan("calculateCommission", initialSpan);
|
||||
try {
|
||||
// ...
|
||||
// You can tag a span
|
||||
|
||||
@@ -91,7 +91,7 @@ public class TraceCallableTests {
|
||||
}
|
||||
|
||||
private Span givenSpanIsAlreadyActive() {
|
||||
return this.tracer.startTrace("http:parent");
|
||||
return this.tracer.createSpan("http:parent");
|
||||
}
|
||||
|
||||
private Callable<Span> thatRetrievesTraceFromThreadLocal() {
|
||||
|
||||
@@ -58,7 +58,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("http:PARENT");
|
||||
Span span = this.tracer.createSpan("http:PARENT");
|
||||
CompletableFuture.allOf(runnablesExecutedViaTraceManagerableExecutorService()).get();
|
||||
this.tracer.close(span);
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@ public class HystrixAnnotationsIntegrationTests {
|
||||
}
|
||||
|
||||
private Span givenASpanInCurrentThread() {
|
||||
return this.tracer.startTrace("http:existing");
|
||||
return this.tracer.createSpan("http:existing");
|
||||
}
|
||||
|
||||
private void whenHystrixCommandAnnotatedMethodGetsExecuted() {
|
||||
|
||||
@@ -80,7 +80,7 @@ public class TraceCommandTests {
|
||||
}
|
||||
|
||||
private Span givenATraceIsPresentInTheCurrentThread() {
|
||||
return this.tracer.joinTrace("http:test",
|
||||
return this.tracer.createSpan("http:test",
|
||||
Span.builder().traceId(EXPECTED_TRACE_ID).build());
|
||||
}
|
||||
|
||||
|
||||
@@ -138,7 +138,7 @@ public class TraceChannelInterceptorTests implements MessageHandler {
|
||||
|
||||
@Test
|
||||
public void headerCreation() {
|
||||
Span span = this.tracer.startTrace("http:testSendMessage", new AlwaysSampler());
|
||||
Span span = this.tracer.createSpan("http:testSendMessage", new AlwaysSampler());
|
||||
this.channel.send(MessageBuilder.withPayload("hi").build());
|
||||
this.tracer.close(span);
|
||||
assertNotNull("message was null", this.message);
|
||||
@@ -154,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("http:testSendMessage", new AlwaysSampler());
|
||||
Span span = this.tracer.createSpan("http:testSendMessage", new AlwaysSampler());
|
||||
this.messagingTemplate.send(MessageBuilder.withPayload("hi").build());
|
||||
this.tracer.close(span);
|
||||
assertNotNull("message was null", this.message);
|
||||
|
||||
@@ -66,7 +66,7 @@ public class TraceContextPropagationChannelInterceptorTests {
|
||||
@Test
|
||||
public void testSpanPropagation() {
|
||||
|
||||
Span span = this.tracer.startTrace("http:testSendMessage", new AlwaysSampler());
|
||||
Span span = this.tracer.createSpan("http:testSendMessage", new AlwaysSampler());
|
||||
this.channel.send(MessageBuilder.withPayload("hi").build());
|
||||
Long expectedSpanId = span.getSpanId();
|
||||
this.tracer.close(span);
|
||||
|
||||
@@ -41,7 +41,7 @@ public class TraceAsyncIntegrationTests {
|
||||
}
|
||||
|
||||
private Span givenASpanInCurrentThread() {
|
||||
return this.tracer.startTrace("http:existing");
|
||||
return this.tracer.createSpan("http:existing");
|
||||
}
|
||||
|
||||
private void whenAsyncProcessingTakesPlace() {
|
||||
|
||||
@@ -127,7 +127,7 @@ public class TraceFilterTests {
|
||||
|
||||
@Test
|
||||
public void continuesSpanInRequestAttr() throws Exception {
|
||||
Span span = this.tracer.startTrace("http:foo");
|
||||
Span span = this.tracer.createSpan("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();
|
||||
|
||||
@@ -74,7 +74,7 @@ public class TraceRestTemplateInterceptorIntegrationTests {
|
||||
@Test
|
||||
public void spanRemovedFromThreadUponException() throws IOException {
|
||||
this.mockWebServer.enqueue(new MockResponse().setSocketPolicy(SocketPolicy.DISCONNECT_AT_START));
|
||||
Span span = this.tracer.startTrace("new trace");
|
||||
Span span = this.tracer.createSpan("new trace");
|
||||
|
||||
try {
|
||||
this.template.getForEntity(
|
||||
|
||||
@@ -110,7 +110,7 @@ public class TraceRestTemplateInterceptorTests {
|
||||
// issue #198
|
||||
@Test
|
||||
public void spanRemovedFromThreadUponException() {
|
||||
Span span = this.tracer.startTrace("new trace");
|
||||
Span span = this.tracer.createSpan("new trace");
|
||||
|
||||
try {
|
||||
this.template.getForEntity("/exception", Map.class).getBody();
|
||||
|
||||
@@ -57,7 +57,7 @@ public class TracePostZuulFilterTests {
|
||||
@Test
|
||||
public void filterPublishesEvent() throws Exception {
|
||||
this.filter.setApplicationEventPublisher(this.publisher);
|
||||
this.tracer.startTrace("http:start");
|
||||
this.tracer.createSpan("http:start");
|
||||
this.filter.run();
|
||||
verify(this.publisher).publishEvent(isA(ClientReceivedEvent.class));
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ public class TracePreZuulFilterTests {
|
||||
|
||||
@Test
|
||||
public void filterAddsHeaders() throws Exception {
|
||||
this.tracer.startTrace("http:start");
|
||||
this.tracer.createSpan("http:start");
|
||||
this.filter.run();
|
||||
RequestContext ctx = RequestContext.getCurrentContext();
|
||||
assertThat(ctx.getZuulRequestHeaders().get(Span.TRACE_ID_NAME),
|
||||
@@ -70,7 +70,7 @@ public class TracePreZuulFilterTests {
|
||||
|
||||
@Test
|
||||
public void notSampledIfNotExportable() throws Exception {
|
||||
this.tracer.startTrace("http:start", NeverSampler.INSTANCE);
|
||||
this.tracer.createSpan("http:start", NeverSampler.INSTANCE);
|
||||
this.filter.run();
|
||||
RequestContext ctx = RequestContext.getCurrentContext();
|
||||
assertThat(ctx.getZuulRequestHeaders().get(Span.TRACE_ID_NAME),
|
||||
|
||||
@@ -76,7 +76,7 @@ public class DefaultTracerTests {
|
||||
DefaultTracer tracer = new DefaultTracer(NeverSampler.INSTANCE, new Random(),
|
||||
this.publisher, new DefaultSpanNamer());
|
||||
|
||||
Span span = tracer.startTrace(CREATE_SIMPLE_TRACE, new AlwaysSampler());
|
||||
Span span = tracer.createSpan(CREATE_SIMPLE_TRACE, new AlwaysSampler());
|
||||
try {
|
||||
importantWork1(tracer);
|
||||
}
|
||||
@@ -114,7 +114,7 @@ public class DefaultTracerTests {
|
||||
public void nonExportable() {
|
||||
DefaultTracer tracer = new DefaultTracer(NeverSampler.INSTANCE, new Random(),
|
||||
this.publisher, this.spanNamer);
|
||||
Span span = tracer.startTrace(CREATE_SIMPLE_TRACE);
|
||||
Span span = tracer.createSpan(CREATE_SIMPLE_TRACE);
|
||||
assertThat(span.isExportable(), is(false));
|
||||
}
|
||||
|
||||
@@ -122,7 +122,7 @@ public class DefaultTracerTests {
|
||||
public void exportable() {
|
||||
DefaultTracer tracer = new DefaultTracer(new AlwaysSampler(), new Random(),
|
||||
this.publisher, this.spanNamer);
|
||||
Span span = tracer.startTrace(CREATE_SIMPLE_TRACE);
|
||||
Span span = tracer.createSpan(CREATE_SIMPLE_TRACE);
|
||||
assertThat(span.isExportable(), is(true));
|
||||
}
|
||||
|
||||
@@ -130,9 +130,9 @@ public class DefaultTracerTests {
|
||||
public void exportableInheritedFromParent() {
|
||||
DefaultTracer tracer = new DefaultTracer(new AlwaysSampler(), new Random(),
|
||||
this.publisher, this.spanNamer);
|
||||
Span span = tracer.startTrace(CREATE_SIMPLE_TRACE, NeverSampler.INSTANCE);
|
||||
Span span = tracer.createSpan(CREATE_SIMPLE_TRACE, NeverSampler.INSTANCE);
|
||||
assertThat(span.isExportable(), is(false));
|
||||
Span child = tracer.joinTrace(CREATE_SIMPLE_TRACE_SPAN_NAME + "/child", span);
|
||||
Span child = tracer.createSpan(CREATE_SIMPLE_TRACE_SPAN_NAME + "/child", span);
|
||||
assertThat(child.isExportable(), is(false));
|
||||
}
|
||||
|
||||
@@ -140,8 +140,8 @@ public class DefaultTracerTests {
|
||||
public void parentNotRemovedIfActiveOnJoin() {
|
||||
DefaultTracer tracer = new DefaultTracer(new AlwaysSampler(), new Random(),
|
||||
this.publisher, this.spanNamer);
|
||||
Span parent = tracer.startTrace(CREATE_SIMPLE_TRACE);
|
||||
Span span = tracer.joinTrace(IMPORTANT_WORK_1, parent);
|
||||
Span parent = tracer.createSpan(CREATE_SIMPLE_TRACE);
|
||||
Span span = tracer.createSpan(IMPORTANT_WORK_1, parent);
|
||||
tracer.close(span);
|
||||
assertThat(tracer.getCurrentSpan(), is(equalTo(parent)));
|
||||
}
|
||||
@@ -152,7 +152,7 @@ public class DefaultTracerTests {
|
||||
this.publisher, this.spanNamer);
|
||||
Span parent = Span.builder().name(CREATE_SIMPLE_TRACE).traceId(1L).spanId(1L)
|
||||
.build();
|
||||
Span span = tracer.joinTrace(IMPORTANT_WORK_1, parent);
|
||||
Span span = tracer.createSpan(IMPORTANT_WORK_1, parent);
|
||||
tracer.close(span);
|
||||
assertThat(tracer.getCurrentSpan(), is(equalTo(null)));
|
||||
}
|
||||
@@ -161,10 +161,10 @@ public class DefaultTracerTests {
|
||||
public void grandParentRestoredAfterAutoClose() {
|
||||
DefaultTracer tracer = new DefaultTracer(new AlwaysSampler(), new Random(),
|
||||
this.publisher, this.spanNamer);
|
||||
Span grandParent = tracer.startTrace(CREATE_SIMPLE_TRACE);
|
||||
Span grandParent = tracer.createSpan(CREATE_SIMPLE_TRACE);
|
||||
Span parent = Span.builder().name(IMPORTANT_WORK_1).traceId(1L).spanId(1L)
|
||||
.build();
|
||||
Span span = tracer.joinTrace(IMPORTANT_WORK_2, parent);
|
||||
Span span = tracer.createSpan(IMPORTANT_WORK_2, parent);
|
||||
tracer.close(span);
|
||||
assertThat(tracer.getCurrentSpan(), is(equalTo(grandParent)));
|
||||
}
|
||||
@@ -207,7 +207,7 @@ public class DefaultTracerTests {
|
||||
}
|
||||
|
||||
private void importantWork1(Tracer tracer) {
|
||||
Span cur = tracer.startTrace(IMPORTANT_WORK_1);
|
||||
Span cur = tracer.createSpan(IMPORTANT_WORK_1);
|
||||
try {
|
||||
Thread.sleep((long) (50 * Math.random()));
|
||||
importantWork2(tracer);
|
||||
@@ -221,7 +221,7 @@ public class DefaultTracerTests {
|
||||
}
|
||||
|
||||
private void importantWork2(Tracer tracer) {
|
||||
Span cur = tracer.startTrace(IMPORTANT_WORK_2);
|
||||
Span cur = tracer.createSpan(IMPORTANT_WORK_2);
|
||||
try {
|
||||
Thread.sleep((long) (50 * Math.random()));
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ ApplicationListener<EmbeddedServletContainerInitializedEvent> {
|
||||
|
||||
@RequestMapping("/traced")
|
||||
public String traced() throws InterruptedException {
|
||||
Span span = this.tracer.startTrace("http:customTraceEndpoint",
|
||||
Span span = this.tracer.createSpan("http:customTraceEndpoint",
|
||||
new AlwaysSampler());
|
||||
int millis = this.random.nextInt(1000);
|
||||
log.info(String.format("Sleeping for [%d] millis", millis));
|
||||
|
||||
@@ -94,7 +94,7 @@ ApplicationListener<EmbeddedServletContainerInitializedEvent> {
|
||||
|
||||
@RequestMapping("/traced")
|
||||
public String traced() throws InterruptedException {
|
||||
Span span = this.tracer.startTrace("http:customTraceEndpoint",
|
||||
Span span = this.tracer.createSpan("http:customTraceEndpoint",
|
||||
new AlwaysSampler());
|
||||
int millis = this.random.nextInt(1000);
|
||||
log.info(String.format("Sleeping for [%d] millis", millis));
|
||||
|
||||
@@ -90,7 +90,7 @@ ApplicationListener<EmbeddedServletContainerInitializedEvent> {
|
||||
|
||||
@RequestMapping("/traced")
|
||||
public String traced() throws InterruptedException {
|
||||
Span span = this.tracer.startTrace("http:customTraceEndpoint",
|
||||
Span span = this.tracer.createSpan("http:customTraceEndpoint",
|
||||
new AlwaysSampler());
|
||||
int millis = this.random.nextInt(1000);
|
||||
log.info(String.format("Sleeping for [%d] millis", millis));
|
||||
|
||||
@@ -76,7 +76,7 @@ public class StreamSpanListenerTests {
|
||||
|
||||
@Test
|
||||
public void acquireAndRelease() {
|
||||
Span context = this.tracer.startTrace("http:foo");
|
||||
Span context = this.tracer.createSpan("http:foo");
|
||||
this.tracer.close(context);
|
||||
assertEquals(1, this.test.spans.size());
|
||||
}
|
||||
@@ -85,7 +85,7 @@ public class StreamSpanListenerTests {
|
||||
public void rpcAnnotations() {
|
||||
Span parent = Span.builder().traceId(1L).name("http:parent").remote(true)
|
||||
.build();
|
||||
Span context = this.tracer.joinTrace("http:child", parent);
|
||||
Span context = this.tracer.createSpan("http:child", parent);
|
||||
this.application.publishEvent(new ClientSentEvent(this, context));
|
||||
this.application
|
||||
.publishEvent(new ServerReceivedEvent(this, parent, context));
|
||||
@@ -98,7 +98,7 @@ public class StreamSpanListenerTests {
|
||||
|
||||
@Test
|
||||
public void nullSpanName() {
|
||||
Span span = this.tracer.startTrace(null);
|
||||
Span span = this.tracer.createSpan(null);
|
||||
this.application.publishEvent(new ClientSentEvent(this, span));
|
||||
this.tracer.close(span);
|
||||
assertEquals(1, this.test.spans.size());
|
||||
@@ -108,7 +108,7 @@ public class StreamSpanListenerTests {
|
||||
|
||||
@Test
|
||||
public void shouldIncreaseNumberOfAcceptedSpans() {
|
||||
Span context = this.tracer.startTrace("http:foo");
|
||||
Span context = this.tracer.createSpan("http:foo");
|
||||
this.tracer.close(context);
|
||||
this.listener.poll();
|
||||
|
||||
|
||||
@@ -120,7 +120,7 @@ public class ZipkinSpanListenerTests {
|
||||
*/
|
||||
@Test
|
||||
public void spanWithoutAnnotationsLogsComponent() {
|
||||
Span context = this.tracer.startTrace("http:foo");
|
||||
Span context = this.tracer.createSpan("http:foo");
|
||||
this.tracer.close(context);
|
||||
assertEquals(1, this.test.spans.size());
|
||||
assertThat(this.test.spans.get(0).binaryAnnotations.get(0).endpoint.serviceName)
|
||||
@@ -129,7 +129,7 @@ public class ZipkinSpanListenerTests {
|
||||
|
||||
@Test
|
||||
public void rpcAnnotations() {
|
||||
Span context = this.tracer.joinTrace("http:child", this.parent);
|
||||
Span context = this.tracer.createSpan("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