Updates to latest Brave, removing deprecated usage

Notably, this avoids `Span.remoteEndpoint` and deprecated test helpers.
This commit is contained in:
Adrian Cole
2018-09-14 13:24:17 +08:00
committed by Adrian Cole
parent 7fc10e80cd
commit e2ec76207f
24 changed files with 180 additions and 90 deletions

View File

@@ -43,7 +43,6 @@ import org.springframework.messaging.support.ExecutorChannelInterceptor;
import org.springframework.messaging.support.GenericMessage;
import org.springframework.messaging.support.MessageHeaderAccessor;
import org.springframework.util.ClassUtils;
import zipkin2.Endpoint;
/**
* This starts and propagates {@link Span.Kind#PRODUCER} span for each message sent (via native
@@ -145,7 +144,7 @@ public final class TracingChannelInterceptor extends ChannelInterceptorAdapter
this.injector.inject(span.context(), headers);
if (!span.isNoop()) {
span.kind(Span.Kind.PRODUCER).name("send").start();
span.remoteEndpoint(Endpoint.newBuilder().serviceName(REMOTE_SERVICE_NAME).build());
span.remoteServiceName(REMOTE_SERVICE_NAME);
addTags(message, span, channel);
}
if (log.isDebugEnabled()) {
@@ -211,7 +210,7 @@ public final class TracingChannelInterceptor extends ChannelInterceptorAdapter
this.injector.inject(span.context(), headers);
if (!span.isNoop()) {
span.kind(Span.Kind.CONSUMER).name("receive").start();
span.remoteEndpoint(Endpoint.newBuilder().serviceName(REMOTE_SERVICE_NAME).build());
span.remoteServiceName(REMOTE_SERVICE_NAME);
addTags(message, span, channel);
}
if (log.isDebugEnabled()) {
@@ -248,7 +247,7 @@ public final class TracingChannelInterceptor extends ChannelInterceptorAdapter
Span consumerSpan = this.tracer.nextSpan(extracted);
if (!consumerSpan.isNoop()) {
consumerSpan.kind(Span.Kind.CONSUMER).start();
consumerSpan.remoteEndpoint(Endpoint.newBuilder().serviceName(REMOTE_SERVICE_NAME).build());
consumerSpan.remoteServiceName(REMOTE_SERVICE_NAME);
addTags(message, consumerSpan, channel);
consumerSpan.finish();
}

View File

@@ -27,7 +27,8 @@ import java.util.concurrent.Future;
import brave.Span;
import brave.Tracer;
import brave.Tracing;
import brave.propagation.StrictCurrentTraceContext;
import brave.propagation.StrictScopeDecorator;
import brave.propagation.ThreadLocalCurrentTraceContext;
import brave.sampler.Sampler;
import org.assertj.core.api.BDDAssertions;
import org.junit.Before;
@@ -53,7 +54,9 @@ public class SpringCloudSleuthDocTests {
ArrayListSpanReporter reporter = new ArrayListSpanReporter();
Tracing tracing = Tracing.newBuilder()
.currentTraceContext(new StrictCurrentTraceContext())
.currentTraceContext(ThreadLocalCurrentTraceContext.newBuilder()
.addScopeDecorator(StrictScopeDecorator.create())
.build())
.sampler(Sampler.ALWAYS_SAMPLE)
.spanReporter(this.reporter)
.build();

View File

@@ -1,7 +1,8 @@
package org.springframework.cloud.sleuth.instrument.async;
import brave.Tracing;
import brave.propagation.StrictCurrentTraceContext;
import brave.propagation.StrictScopeDecorator;
import brave.propagation.ThreadLocalCurrentTraceContext;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.reflect.MethodSignature;
import org.assertj.core.api.BDDAssertions;
@@ -19,7 +20,9 @@ public class TraceAsyncAspectTest {
ArrayListSpanReporter reporter = new ArrayListSpanReporter();
Tracing tracing = Tracing.newBuilder()
.currentTraceContext(new StrictCurrentTraceContext())
.currentTraceContext(ThreadLocalCurrentTraceContext.newBuilder()
.addScopeDecorator(StrictScopeDecorator.create())
.build())
.spanReporter(this.reporter)
.build();
ProceedingJoinPoint point = Mockito.mock(ProceedingJoinPoint.class);

View File

@@ -23,7 +23,8 @@ import java.util.concurrent.atomic.AtomicBoolean;
import brave.Span;
import brave.Tracer;
import brave.Tracing;
import brave.propagation.StrictCurrentTraceContext;
import brave.propagation.StrictScopeDecorator;
import brave.propagation.ThreadLocalCurrentTraceContext;
import org.assertj.core.api.BDDAssertions;
import org.awaitility.Awaitility;
import org.junit.Test;
@@ -37,7 +38,9 @@ public class TraceAsyncListenableTaskExecutorTest {
AsyncListenableTaskExecutor delegate = new SimpleAsyncTaskExecutor();
Tracing tracing = Tracing.newBuilder()
.currentTraceContext(new StrictCurrentTraceContext())
.currentTraceContext(ThreadLocalCurrentTraceContext.newBuilder()
.addScopeDecorator(StrictScopeDecorator.create())
.build())
.build();
Tracer tracer = this.tracing.tracer();
TraceAsyncListenableTaskExecutor traceAsyncListenableTaskExecutor = new TraceAsyncListenableTaskExecutor(

View File

@@ -23,7 +23,8 @@ import java.util.concurrent.Executors;
import brave.Span;
import brave.Tracer;
import brave.Tracing;
import brave.propagation.StrictCurrentTraceContext;
import brave.propagation.StrictScopeDecorator;
import brave.propagation.ThreadLocalCurrentTraceContext;
import org.junit.After;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -40,7 +41,9 @@ public class TraceCallableTests {
ExecutorService executor = Executors.newSingleThreadExecutor();
ArrayListSpanReporter reporter = new ArrayListSpanReporter();
Tracing tracing = Tracing.newBuilder()
.currentTraceContext(new StrictCurrentTraceContext())
.currentTraceContext(ThreadLocalCurrentTraceContext.newBuilder()
.addScopeDecorator(StrictScopeDecorator.create())
.build())
.spanReporter(this.reporter)
.build();
Tracer tracer = this.tracing.tracer();

View File

@@ -23,7 +23,8 @@ import java.util.concurrent.atomic.AtomicReference;
import brave.Span;
import brave.Tracer;
import brave.Tracing;
import brave.propagation.StrictCurrentTraceContext;
import brave.propagation.StrictScopeDecorator;
import brave.propagation.ThreadLocalCurrentTraceContext;
import org.junit.After;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -40,7 +41,9 @@ public class TraceRunnableTests {
ExecutorService executor = Executors.newSingleThreadExecutor();
ArrayListSpanReporter reporter = new ArrayListSpanReporter();
Tracing tracing = Tracing.newBuilder()
.currentTraceContext(new StrictCurrentTraceContext())
.currentTraceContext(ThreadLocalCurrentTraceContext.newBuilder()
.addScopeDecorator(StrictScopeDecorator.create())
.build())
.spanReporter(this.reporter)
.build();
Tracer tracer = this.tracing.tracer();

View File

@@ -32,7 +32,8 @@ import brave.ScopedSpan;
import brave.Span;
import brave.Tracer;
import brave.Tracing;
import brave.propagation.StrictCurrentTraceContext;
import brave.propagation.StrictScopeDecorator;
import brave.propagation.ThreadLocalCurrentTraceContext;
import org.assertj.core.api.BDDAssertions;
import org.junit.After;
import org.junit.Before;
@@ -60,7 +61,9 @@ public class TraceableExecutorServiceTests {
ExecutorService traceManagerableExecutorService;
ArrayListSpanReporter reporter = new ArrayListSpanReporter();
Tracing tracing = Tracing.newBuilder()
.currentTraceContext(new StrictCurrentTraceContext())
.currentTraceContext(ThreadLocalCurrentTraceContext.newBuilder()
.addScopeDecorator(StrictScopeDecorator.create())
.build())
.spanReporter(this.reporter)
.build();
Tracer tracer = this.tracing.tracer();

View File

@@ -22,7 +22,8 @@ import java.util.concurrent.TimeUnit;
import java.util.function.Predicate;
import brave.Tracing;
import brave.propagation.StrictCurrentTraceContext;
import brave.propagation.StrictScopeDecorator;
import brave.propagation.ThreadLocalCurrentTraceContext;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -46,7 +47,9 @@ import static org.mockito.BDDMockito.then;
public class TraceableScheduledExecutorServiceTest {
Tracing tracing = Tracing.newBuilder()
.currentTraceContext(new StrictCurrentTraceContext())
.currentTraceContext(ThreadLocalCurrentTraceContext.newBuilder()
.addScopeDecorator(StrictScopeDecorator.create())
.build())
.build();
@Mock
BeanFactory beanFactory;

View File

@@ -21,7 +21,8 @@ import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
import brave.Tracing;
import brave.propagation.StrictCurrentTraceContext;
import brave.propagation.StrictScopeDecorator;
import brave.propagation.ThreadLocalCurrentTraceContext;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -51,7 +52,9 @@ public class SleuthHystrixConcurrencyStrategyTest {
ArrayListSpanReporter reporter = new ArrayListSpanReporter();
Tracing tracing = Tracing.newBuilder()
.currentTraceContext(new StrictCurrentTraceContext())
.currentTraceContext(ThreadLocalCurrentTraceContext.newBuilder()
.addScopeDecorator(StrictScopeDecorator.create())
.build())
.spanReporter(this.reporter)
.build();

View File

@@ -22,8 +22,9 @@ import java.util.concurrent.atomic.AtomicReference;
import brave.Span;
import brave.Tracer;
import brave.Tracing;
import brave.propagation.StrictCurrentTraceContext;
import brave.sampler.Sampler;
import brave.propagation.StrictScopeDecorator;
import brave.propagation.ThreadLocalCurrentTraceContext;
import com.netflix.hystrix.HystrixCommand;
import com.netflix.hystrix.HystrixCommandKey;
import com.netflix.hystrix.HystrixCommandProperties;
@@ -42,7 +43,9 @@ public class TraceCommandTests {
ArrayListSpanReporter reporter = new ArrayListSpanReporter();
Tracing tracing = Tracing.newBuilder()
.currentTraceContext(new StrictCurrentTraceContext())
.currentTraceContext(ThreadLocalCurrentTraceContext.newBuilder()
.addScopeDecorator(StrictScopeDecorator.create())
.build())
.spanReporter(this.reporter)
.sampler(Sampler.ALWAYS_SAMPLE)
.build();

View File

@@ -25,7 +25,8 @@ import javax.annotation.PreDestroy;
import brave.Span;
import brave.Tracer;
import brave.Tracing;
import brave.propagation.StrictCurrentTraceContext;
import brave.propagation.StrictScopeDecorator;
import brave.propagation.ThreadLocalCurrentTraceContext;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -135,7 +136,9 @@ public class ITTracingChannelInterceptor implements MessageHandler {
@Bean Tracing tracing() {
return Tracing.newBuilder()
.currentTraceContext(new StrictCurrentTraceContext())
.currentTraceContext(ThreadLocalCurrentTraceContext.newBuilder()
.addScopeDecorator(StrictScopeDecorator.create())
.build())
.spanReporter(spans()::add).build();
}

View File

@@ -23,7 +23,8 @@ import java.util.List;
import java.util.Map;
import brave.Tracing;
import brave.propagation.StrictCurrentTraceContext;
import brave.propagation.StrictScopeDecorator;
import brave.propagation.ThreadLocalCurrentTraceContext;
import org.junit.After;
import org.junit.Test;
import org.springframework.integration.channel.DirectChannel;
@@ -49,7 +50,10 @@ public class TracingChannelInterceptorTest {
List<Span> spans = new ArrayList<>();
ChannelInterceptor interceptor = TracingChannelInterceptor.create(Tracing.newBuilder()
.currentTraceContext(new StrictCurrentTraceContext()).spanReporter(spans::add)
.currentTraceContext(ThreadLocalCurrentTraceContext.newBuilder()
.addScopeDecorator(StrictScopeDecorator.create())
.build())
.spanReporter(spans::add)
.build());
QueueChannel channel = new QueueChannel();

View File

@@ -24,8 +24,6 @@ import brave.Tracing;
import brave.opentracing.BraveSpan;
import brave.opentracing.BraveSpanContext;
import brave.opentracing.BraveTracer;
import brave.propagation.CurrentTraceContext;
import brave.propagation.StrictCurrentTraceContext;
import brave.propagation.TraceContext;
import brave.sampler.Sampler;
import io.opentracing.Scope;

View File

@@ -28,7 +28,8 @@ import java.util.concurrent.ThreadFactory;
import brave.Tracer;
import brave.Tracing;
import brave.propagation.StrictCurrentTraceContext;
import brave.propagation.StrictScopeDecorator;
import brave.propagation.ThreadLocalCurrentTraceContext;
import rx.functions.Action0;
import rx.plugins.RxJavaErrorHandler;
import rx.plugins.RxJavaObservableExecutionHook;
@@ -50,7 +51,9 @@ public class SleuthRxJavaSchedulersHookTests {
List<String> threadsToIgnore = new ArrayList<>();
ArrayListSpanReporter reporter = new ArrayListSpanReporter();
Tracing tracing = Tracing.newBuilder()
.currentTraceContext(new StrictCurrentTraceContext())
.currentTraceContext(ThreadLocalCurrentTraceContext.newBuilder()
.addScopeDecorator(StrictScopeDecorator.create())
.build())
.spanReporter(this.reporter)
.build();
Tracer tracer = this.tracing.tracer();

View File

@@ -25,7 +25,8 @@ import brave.Span;
import brave.Tracer;
import brave.Tracing;
import brave.http.HttpTracing;
import brave.propagation.StrictCurrentTraceContext;
import brave.propagation.StrictScopeDecorator;
import brave.propagation.ThreadLocalCurrentTraceContext;
import brave.sampler.Sampler;
import brave.servlet.TracingFilter;
import org.junit.After;
@@ -60,7 +61,9 @@ public class TraceFilterTests {
ArrayListSpanReporter reporter = new ArrayListSpanReporter();
Tracing tracing = Tracing.newBuilder()
.currentTraceContext(new StrictCurrentTraceContext())
.currentTraceContext(ThreadLocalCurrentTraceContext.newBuilder()
.addScopeDecorator(StrictScopeDecorator.create())
.build())
.spanReporter(this.reporter)
.build();
Tracer tracer = this.tracing.tracer();
@@ -108,7 +111,9 @@ public class TraceFilterTests {
private Filter neverSampleFilter() {
Tracing tracing = Tracing.newBuilder()
.currentTraceContext(new StrictCurrentTraceContext())
.currentTraceContext(ThreadLocalCurrentTraceContext.newBuilder()
.addScopeDecorator(StrictScopeDecorator.create())
.build())
.spanReporter(this.reporter)
.sampler(Sampler.NEVER_SAMPLE)
.supportsJoin(false)
@@ -235,7 +240,9 @@ public class TraceFilterTests {
@Test
public void createsChildFromHeadersWhenJoinUnsupported() throws Exception {
Tracing tracing = Tracing.newBuilder()
.currentTraceContext(new StrictCurrentTraceContext())
.currentTraceContext(ThreadLocalCurrentTraceContext.newBuilder()
.addScopeDecorator(StrictScopeDecorator.create())
.build())
.spanReporter(this.reporter)
.supportsJoin(false)
.build();

View File

@@ -25,8 +25,9 @@ import brave.Span;
import brave.Tracer;
import brave.Tracing;
import brave.http.HttpTracing;
import brave.propagation.StrictCurrentTraceContext;
import brave.sampler.Sampler;
import brave.propagation.StrictScopeDecorator;
import brave.propagation.ThreadLocalCurrentTraceContext;
import brave.spring.web.TracingClientHttpRequestInterceptor;
import org.apache.commons.lang3.StringUtils;
import org.junit.After;
@@ -60,7 +61,9 @@ public class TraceRestTemplateInterceptorTests {
new MockMvcClientHttpRequestFactory(this.mockMvc));
ArrayListSpanReporter reporter = new ArrayListSpanReporter();
Tracing tracing = Tracing.newBuilder()
.currentTraceContext(new StrictCurrentTraceContext())
.currentTraceContext(ThreadLocalCurrentTraceContext.newBuilder()
.addScopeDecorator(StrictScopeDecorator.create())
.build())
.spanReporter(this.reporter)
.build();
Tracer tracer = this.tracing.tracer();
@@ -136,7 +139,9 @@ public class TraceRestTemplateInterceptorTests {
@Test
public void notSampledHeaderAddedWhenNotExportable() {
Tracing tracing = Tracing.newBuilder()
.currentTraceContext(new StrictCurrentTraceContext())
.currentTraceContext(ThreadLocalCurrentTraceContext.newBuilder()
.addScopeDecorator(StrictScopeDecorator.create())
.build())
.spanReporter(this.reporter)
.sampler(Sampler.NEVER_SAMPLE)
.build();

View File

@@ -36,7 +36,8 @@ import brave.Span;
import brave.Tracer;
import brave.Tracing;
import brave.http.HttpTracing;
import brave.propagation.StrictCurrentTraceContext;
import brave.propagation.StrictScopeDecorator;
import brave.propagation.ThreadLocalCurrentTraceContext;
import brave.spring.web.TracingClientHttpRequestInterceptor;
import okhttp3.mockwebserver.MockResponse;
import okhttp3.mockwebserver.MockWebServer;
@@ -53,7 +54,9 @@ public class TraceRestTemplateInterceptorIntegrationTests {
ArrayListSpanReporter reporter = new ArrayListSpanReporter();
Tracing tracing = Tracing.newBuilder()
.currentTraceContext(new StrictCurrentTraceContext())
.currentTraceContext(ThreadLocalCurrentTraceContext.newBuilder()
.addScopeDecorator(StrictScopeDecorator.create())
.build())
.spanReporter(this.reporter)
.build();
Tracer tracer = this.tracing.tracer();

View File

@@ -23,7 +23,8 @@ import java.util.concurrent.atomic.AtomicInteger;
import brave.Tracing;
import brave.http.HttpTracing;
import brave.propagation.StrictCurrentTraceContext;
import brave.propagation.StrictScopeDecorator;
import brave.propagation.ThreadLocalCurrentTraceContext;
import feign.Client;
import feign.Feign;
import feign.FeignException;
@@ -60,7 +61,9 @@ public class FeignRetriesTests {
ArrayListSpanReporter reporter = new ArrayListSpanReporter();
Tracing tracing = Tracing.newBuilder()
.currentTraceContext(new StrictCurrentTraceContext())
.currentTraceContext(ThreadLocalCurrentTraceContext.newBuilder()
.addScopeDecorator(StrictScopeDecorator.create())
.build())
.spanReporter(this.reporter)
.build();
HttpTracing httpTracing = HttpTracing.newBuilder(this.tracing)

View File

@@ -20,7 +20,8 @@ import java.io.IOException;
import brave.Tracing;
import brave.http.HttpTracing;
import brave.propagation.StrictCurrentTraceContext;
import brave.propagation.StrictScopeDecorator;
import brave.propagation.ThreadLocalCurrentTraceContext;
import feign.Client;
import org.aspectj.lang.ProceedingJoinPoint;
import org.junit.Before;
@@ -46,7 +47,9 @@ public class TraceFeignAspectTests {
@Mock ProceedingJoinPoint pjp;
@Mock TraceLoadBalancerFeignClient traceLoadBalancerFeignClient;
Tracing tracing = Tracing.newBuilder()
.currentTraceContext(new StrictCurrentTraceContext())
.currentTraceContext(ThreadLocalCurrentTraceContext.newBuilder()
.addScopeDecorator(StrictScopeDecorator.create())
.build())
.build();
HttpTracing httpTracing = HttpTracing.newBuilder(this.tracing)
.clientParser(SleuthHttpParserAccessor.getClient())

View File

@@ -24,7 +24,8 @@ import brave.Span;
import brave.Tracer;
import brave.Tracing;
import brave.http.HttpTracing;
import brave.propagation.StrictCurrentTraceContext;
import brave.propagation.StrictScopeDecorator;
import brave.propagation.ThreadLocalCurrentTraceContext;
import feign.Client;
import feign.Request;
import org.assertj.core.api.BDDAssertions;
@@ -49,7 +50,9 @@ public class TracingFeignClientTests {
ArrayListSpanReporter reporter = new ArrayListSpanReporter();
@Mock BeanFactory beanFactory;
Tracing tracing = Tracing.newBuilder()
.currentTraceContext(new StrictCurrentTraceContext())
.currentTraceContext(ThreadLocalCurrentTraceContext.newBuilder()
.addScopeDecorator(StrictScopeDecorator.create())
.build())
.spanReporter(this.reporter)
.build();
Tracer tracer = this.tracing.tracer();

View File

@@ -25,7 +25,8 @@ import brave.Span;
import brave.Tracer;
import brave.Tracing;
import brave.http.HttpTracing;
import brave.propagation.StrictCurrentTraceContext;
import brave.propagation.StrictScopeDecorator;
import brave.propagation.ThreadLocalCurrentTraceContext;
import com.netflix.zuul.context.RequestContext;
import com.netflix.zuul.monitoring.TracerFactory;
import org.junit.After;
@@ -53,7 +54,9 @@ public class TracePostZuulFilterTests {
ArrayListSpanReporter reporter = new ArrayListSpanReporter();
Tracing tracing = Tracing.newBuilder()
.currentTraceContext(new StrictCurrentTraceContext())
.currentTraceContext(ThreadLocalCurrentTraceContext.newBuilder()
.addScopeDecorator(StrictScopeDecorator.create())
.build())
.spanReporter(this.reporter)
.build();
HttpTracing httpTracing = HttpTracing.newBuilder(this.tracing)