Updates to latest brave and removes all static thread local use (#1594)
This commit is contained in:
@@ -34,7 +34,7 @@
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<spring-boot.version>2.1.10.RELEASE</spring-boot.version>
|
||||
<brave.version>5.10.1</brave.version>
|
||||
<brave.version>5.11.0</brave.version>
|
||||
<okhttp.version>3.11.0</okhttp.version>
|
||||
</properties>
|
||||
|
||||
|
||||
2
pom.xml
2
pom.xml
@@ -264,7 +264,7 @@
|
||||
<spring-cloud-stream.version>Fishtown.SR4</spring-cloud-stream.version>
|
||||
<spring-cloud-netflix.version>2.1.6.BUILD-SNAPSHOT</spring-cloud-netflix.version>
|
||||
<spring-cloud-openfeign.version>2.1.6.BUILD-SNAPSHOT</spring-cloud-openfeign.version>
|
||||
<brave.version>5.10.1</brave.version>
|
||||
<brave.version>5.11.0</brave.version>
|
||||
<spring-security-boot-autoconfigure.version>2.1.2.RELEASE
|
||||
</spring-security-boot-autoconfigure.version>
|
||||
|
||||
|
||||
@@ -195,7 +195,7 @@
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.zipkin.brave</groupId>
|
||||
<artifactId>brave-context-log4j2</artifactId>
|
||||
<artifactId>brave-context-slf4j</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.zipkin.brave</groupId>
|
||||
|
||||
@@ -49,7 +49,7 @@ public class TraceAutoConfigurationPropagationCustomizationTests {
|
||||
this.contextRunner.withPropertyValues("spring.sleuth.baggage-keys=my-baggage")
|
||||
.run((context) -> {
|
||||
BDDAssertions.then(context.getBean(Propagation.Factory.class))
|
||||
.hasFieldOrPropertyWithValue("delegate",
|
||||
.hasFieldOrPropertyWithValue("delegate.delegate",
|
||||
B3Propagation.FACTORY);
|
||||
});
|
||||
}
|
||||
@@ -81,7 +81,7 @@ public class TraceAutoConfigurationPropagationCustomizationTests {
|
||||
.withUserConfiguration(CustomPropagationFactoryBuilderConfig.class)
|
||||
.run((context) -> {
|
||||
BDDAssertions.then(context.getBean(Propagation.Factory.class))
|
||||
.hasFieldOrPropertyWithValue("delegate",
|
||||
.hasFieldOrPropertyWithValue("delegate.delegate",
|
||||
B3SinglePropagation.FACTORY);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -27,10 +27,10 @@ import java.util.concurrent.Future;
|
||||
import brave.Span;
|
||||
import brave.Tracer;
|
||||
import brave.Tracing;
|
||||
import brave.propagation.StrictScopeDecorator;
|
||||
import brave.propagation.ThreadLocalCurrentTraceContext;
|
||||
import brave.propagation.StrictCurrentTraceContext;
|
||||
import brave.sampler.Sampler;
|
||||
import org.assertj.core.api.BDDAssertions;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -55,9 +55,9 @@ public class SpringCloudSleuthDocTests {
|
||||
|
||||
ArrayListSpanReporter reporter = new ArrayListSpanReporter();
|
||||
|
||||
Tracing tracing = Tracing.newBuilder()
|
||||
.currentTraceContext(ThreadLocalCurrentTraceContext.newBuilder()
|
||||
.addScopeDecorator(StrictScopeDecorator.create()).build())
|
||||
StrictCurrentTraceContext currentTraceContext = StrictCurrentTraceContext.create();
|
||||
|
||||
Tracing tracing = Tracing.newBuilder().currentTraceContext(this.currentTraceContext)
|
||||
.sampler(Sampler.ALWAYS_SAMPLE).spanReporter(this.reporter).build();
|
||||
|
||||
Tracer tracer = this.tracing.tracer();
|
||||
@@ -67,6 +67,12 @@ public class SpringCloudSleuthDocTests {
|
||||
this.reporter.clear();
|
||||
}
|
||||
|
||||
@After
|
||||
public void close() {
|
||||
this.tracing.close();
|
||||
this.currentTraceContext.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_set_runnable_name_to_annotated_value()
|
||||
throws ExecutionException, InterruptedException {
|
||||
|
||||
@@ -32,6 +32,7 @@ import java.util.concurrent.TimeoutException;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import brave.Tracing;
|
||||
import brave.propagation.StrictCurrentTraceContext;
|
||||
import org.aopalliance.aop.Advice;
|
||||
import org.assertj.core.api.BDDAssertions;
|
||||
import org.junit.After;
|
||||
@@ -65,7 +66,10 @@ public class ExecutorBeanPostProcessorTests {
|
||||
@Mock
|
||||
BeanFactory beanFactory;
|
||||
|
||||
Tracing tracing = Tracing.newBuilder().build();
|
||||
StrictCurrentTraceContext currentTraceContext = StrictCurrentTraceContext.create();
|
||||
|
||||
Tracing tracing = Tracing.newBuilder().currentTraceContext(this.currentTraceContext)
|
||||
.build();
|
||||
|
||||
private SleuthAsyncProperties sleuthAsyncProperties;
|
||||
|
||||
@@ -79,6 +83,7 @@ public class ExecutorBeanPostProcessorTests {
|
||||
@After
|
||||
public void clear() {
|
||||
this.tracing.close();
|
||||
this.currentTraceContext.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -24,8 +24,8 @@ import java.util.concurrent.RejectedExecutionHandler;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
|
||||
import brave.Tracing;
|
||||
import brave.propagation.StrictScopeDecorator;
|
||||
import brave.propagation.ThreadLocalCurrentTraceContext;
|
||||
import brave.propagation.StrictCurrentTraceContext;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -43,9 +43,9 @@ import org.springframework.util.ErrorHandler;
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class LazyTraceThreadPoolTaskSchedulerTests {
|
||||
|
||||
Tracing tracing = Tracing.newBuilder()
|
||||
.currentTraceContext(ThreadLocalCurrentTraceContext.newBuilder()
|
||||
.addScopeDecorator(StrictScopeDecorator.create()).build())
|
||||
StrictCurrentTraceContext currentTraceContext = StrictCurrentTraceContext.create();
|
||||
|
||||
Tracing tracing = Tracing.newBuilder().currentTraceContext(currentTraceContext)
|
||||
.build();
|
||||
|
||||
@Mock
|
||||
@@ -62,6 +62,13 @@ public class LazyTraceThreadPoolTaskSchedulerTests {
|
||||
this.delegate);
|
||||
}
|
||||
|
||||
@After
|
||||
public void close() {
|
||||
this.executor.shutdown();
|
||||
this.tracing.close();
|
||||
this.currentTraceContext.close();
|
||||
}
|
||||
|
||||
BeanFactory beanFactory() {
|
||||
BDDMockito.given(this.beanFactory.getBean(Tracing.class))
|
||||
.willReturn(this.tracing);
|
||||
|
||||
@@ -17,11 +17,11 @@
|
||||
package org.springframework.cloud.sleuth.instrument.async;
|
||||
|
||||
import brave.Tracing;
|
||||
import brave.propagation.StrictScopeDecorator;
|
||||
import brave.propagation.ThreadLocalCurrentTraceContext;
|
||||
import brave.propagation.StrictCurrentTraceContext;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.reflect.MethodSignature;
|
||||
import org.assertj.core.api.BDDAssertions;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.BDDMockito;
|
||||
@@ -35,11 +35,11 @@ import org.springframework.cloud.sleuth.util.ArrayListSpanReporter;
|
||||
*/
|
||||
public class TraceAsyncAspectTest {
|
||||
|
||||
StrictCurrentTraceContext currentTraceContext = StrictCurrentTraceContext.create();
|
||||
|
||||
ArrayListSpanReporter reporter = new ArrayListSpanReporter();
|
||||
|
||||
Tracing tracing = Tracing.newBuilder()
|
||||
.currentTraceContext(ThreadLocalCurrentTraceContext.newBuilder()
|
||||
.addScopeDecorator(StrictScopeDecorator.create()).build())
|
||||
Tracing tracing = Tracing.newBuilder().currentTraceContext(this.currentTraceContext)
|
||||
.spanReporter(this.reporter).build();
|
||||
|
||||
ProceedingJoinPoint point = Mockito.mock(ProceedingJoinPoint.class);
|
||||
@@ -54,6 +54,12 @@ public class TraceAsyncAspectTest {
|
||||
BDDMockito.given(this.point.getTarget()).willReturn("");
|
||||
}
|
||||
|
||||
@After
|
||||
public void close() {
|
||||
this.tracing.close();
|
||||
this.currentTraceContext.close();
|
||||
}
|
||||
|
||||
// Issue#926
|
||||
@Test
|
||||
public void should_work() throws Throwable {
|
||||
|
||||
@@ -23,10 +23,10 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import brave.Span;
|
||||
import brave.Tracer;
|
||||
import brave.Tracing;
|
||||
import brave.propagation.StrictScopeDecorator;
|
||||
import brave.propagation.ThreadLocalCurrentTraceContext;
|
||||
import brave.propagation.StrictCurrentTraceContext;
|
||||
import org.assertj.core.api.BDDAssertions;
|
||||
import org.awaitility.Awaitility;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.core.task.AsyncListenableTaskExecutor;
|
||||
@@ -39,9 +39,9 @@ public class TraceAsyncListenableTaskExecutorTest {
|
||||
|
||||
AsyncListenableTaskExecutor delegate = new SimpleAsyncTaskExecutor();
|
||||
|
||||
Tracing tracing = Tracing.newBuilder()
|
||||
.currentTraceContext(ThreadLocalCurrentTraceContext.newBuilder()
|
||||
.addScopeDecorator(StrictScopeDecorator.create()).build())
|
||||
StrictCurrentTraceContext currentTraceContext = StrictCurrentTraceContext.create();
|
||||
|
||||
Tracing tracing = Tracing.newBuilder().currentTraceContext(currentTraceContext)
|
||||
.build();
|
||||
|
||||
Tracer tracer = this.tracing.tracer();
|
||||
@@ -49,6 +49,12 @@ public class TraceAsyncListenableTaskExecutorTest {
|
||||
TraceAsyncListenableTaskExecutor traceAsyncListenableTaskExecutor = new TraceAsyncListenableTaskExecutor(
|
||||
this.delegate, this.tracing);
|
||||
|
||||
@After
|
||||
public void close() {
|
||||
this.tracing.close();
|
||||
this.currentTraceContext.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_submit_listenable_trace_runnable() throws Exception {
|
||||
AtomicBoolean executed = new AtomicBoolean();
|
||||
|
||||
@@ -23,8 +23,7 @@ import java.util.concurrent.Executors;
|
||||
import brave.Span;
|
||||
import brave.Tracer;
|
||||
import brave.Tracing;
|
||||
import brave.propagation.StrictScopeDecorator;
|
||||
import brave.propagation.ThreadLocalCurrentTraceContext;
|
||||
import brave.propagation.StrictCurrentTraceContext;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -41,20 +40,21 @@ public class TraceCallableTests {
|
||||
|
||||
ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||
|
||||
StrictCurrentTraceContext currentTraceContext = StrictCurrentTraceContext.create();
|
||||
|
||||
ArrayListSpanReporter reporter = new ArrayListSpanReporter();
|
||||
|
||||
Tracing tracing = Tracing.newBuilder()
|
||||
.currentTraceContext(ThreadLocalCurrentTraceContext.newBuilder()
|
||||
.addScopeDecorator(StrictScopeDecorator.create()).build())
|
||||
Tracing tracing = Tracing.newBuilder().currentTraceContext(this.currentTraceContext)
|
||||
.spanReporter(this.reporter).build();
|
||||
|
||||
Tracer tracer = this.tracing.tracer();
|
||||
|
||||
@After
|
||||
public void clean() {
|
||||
this.executor.shutdown();
|
||||
this.tracing.close();
|
||||
this.reporter.clear();
|
||||
this.executor.shutdown();
|
||||
this.currentTraceContext.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -23,8 +23,7 @@ import java.util.concurrent.atomic.AtomicReference;
|
||||
import brave.Span;
|
||||
import brave.Tracer;
|
||||
import brave.Tracing;
|
||||
import brave.propagation.StrictScopeDecorator;
|
||||
import brave.propagation.ThreadLocalCurrentTraceContext;
|
||||
import brave.propagation.StrictCurrentTraceContext;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -41,20 +40,21 @@ public class TraceRunnableTests {
|
||||
|
||||
ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||
|
||||
StrictCurrentTraceContext currentTraceContext = StrictCurrentTraceContext.create();
|
||||
|
||||
ArrayListSpanReporter reporter = new ArrayListSpanReporter();
|
||||
|
||||
Tracing tracing = Tracing.newBuilder()
|
||||
.currentTraceContext(ThreadLocalCurrentTraceContext.newBuilder()
|
||||
.addScopeDecorator(StrictScopeDecorator.create()).build())
|
||||
Tracing tracing = Tracing.newBuilder().currentTraceContext(this.currentTraceContext)
|
||||
.spanReporter(this.reporter).build();
|
||||
|
||||
Tracer tracer = this.tracing.tracer();
|
||||
|
||||
@After
|
||||
public void clean() {
|
||||
this.executor.shutdown();
|
||||
this.tracing.close();
|
||||
this.reporter.clear();
|
||||
this.executor.shutdown();
|
||||
this.currentTraceContext.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -29,11 +29,10 @@ import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import brave.ScopedSpan;
|
||||
import brave.Span;
|
||||
import brave.Tracer;
|
||||
import brave.Tracing;
|
||||
import brave.propagation.StrictScopeDecorator;
|
||||
import brave.propagation.ThreadLocalCurrentTraceContext;
|
||||
import brave.propagation.StrictCurrentTraceContext;
|
||||
import brave.propagation.TraceContext;
|
||||
import org.assertj.core.api.BDDAssertions;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
@@ -65,11 +64,11 @@ public class TraceableExecutorServiceTests {
|
||||
|
||||
ExecutorService traceManagerableExecutorService;
|
||||
|
||||
StrictCurrentTraceContext currentTraceContext = StrictCurrentTraceContext.create();
|
||||
|
||||
ArrayListSpanReporter reporter = new ArrayListSpanReporter();
|
||||
|
||||
Tracing tracing = Tracing.newBuilder()
|
||||
.currentTraceContext(ThreadLocalCurrentTraceContext.newBuilder()
|
||||
.addScopeDecorator(StrictScopeDecorator.create()).build())
|
||||
Tracing tracing = Tracing.newBuilder().currentTraceContext(this.currentTraceContext)
|
||||
.spanReporter(this.reporter).build();
|
||||
|
||||
Tracer tracer = this.tracing.tracer();
|
||||
@@ -85,12 +84,11 @@ public class TraceableExecutorServiceTests {
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
public void close() {
|
||||
this.traceManagerableExecutorService.shutdown();
|
||||
this.executorService.shutdown();
|
||||
if (Tracing.current() != null) {
|
||||
Tracing.current().close();
|
||||
}
|
||||
this.tracing.close();
|
||||
this.currentTraceContext.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -244,9 +242,9 @@ public class TraceableExecutorServiceTests {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
Span span = Tracing.currentTracer().currentSpan();
|
||||
this.traceIds.add(span.context().traceId());
|
||||
this.spanIds.add(span.context().spanId());
|
||||
TraceContext context = currentTraceContext.get();
|
||||
this.traceIds.add(context.traceId());
|
||||
this.spanIds.add(context.spanId());
|
||||
}
|
||||
|
||||
void clear() {
|
||||
|
||||
@@ -22,8 +22,8 @@ import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import brave.Tracing;
|
||||
import brave.propagation.StrictScopeDecorator;
|
||||
import brave.propagation.ThreadLocalCurrentTraceContext;
|
||||
import brave.propagation.StrictCurrentTraceContext;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -48,9 +48,9 @@ import static org.mockito.Mockito.never;
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class TraceableScheduledExecutorServiceTest {
|
||||
|
||||
Tracing tracing = Tracing.newBuilder()
|
||||
.currentTraceContext(ThreadLocalCurrentTraceContext.newBuilder()
|
||||
.addScopeDecorator(StrictScopeDecorator.create()).build())
|
||||
StrictCurrentTraceContext currentTraceContext = StrictCurrentTraceContext.create();
|
||||
|
||||
Tracing tracing = Tracing.newBuilder().currentTraceContext(this.currentTraceContext)
|
||||
.build();
|
||||
|
||||
@Mock
|
||||
@@ -67,6 +67,12 @@ public class TraceableScheduledExecutorServiceTest {
|
||||
beanFactory();
|
||||
}
|
||||
|
||||
@After
|
||||
public void close() {
|
||||
this.tracing.close();
|
||||
this.currentTraceContext.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_schedule_a_trace_runnable() throws Exception {
|
||||
this.traceableScheduledExecutorService.schedule(aRunnable(), 1L, TimeUnit.DAYS);
|
||||
|
||||
@@ -21,8 +21,7 @@ import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import brave.Tracing;
|
||||
import brave.propagation.StrictScopeDecorator;
|
||||
import brave.propagation.ThreadLocalCurrentTraceContext;
|
||||
import brave.propagation.StrictCurrentTraceContext;
|
||||
import com.netflix.hystrix.HystrixThreadPoolKey;
|
||||
import com.netflix.hystrix.HystrixThreadPoolProperties;
|
||||
import com.netflix.hystrix.strategy.HystrixPlugins;
|
||||
@@ -52,9 +51,9 @@ public class SleuthHystrixConcurrencyStrategyTest {
|
||||
|
||||
ArrayListSpanReporter reporter = new ArrayListSpanReporter();
|
||||
|
||||
Tracing tracing = Tracing.newBuilder()
|
||||
.currentTraceContext(ThreadLocalCurrentTraceContext.newBuilder()
|
||||
.addScopeDecorator(StrictScopeDecorator.create()).build())
|
||||
StrictCurrentTraceContext currentTraceContext = StrictCurrentTraceContext.create();
|
||||
|
||||
Tracing tracing = Tracing.newBuilder().currentTraceContext(this.currentTraceContext)
|
||||
.spanReporter(this.reporter).build();
|
||||
|
||||
@Before
|
||||
@@ -62,6 +61,7 @@ public class SleuthHystrixConcurrencyStrategyTest {
|
||||
public void setup() {
|
||||
HystrixPlugins.reset();
|
||||
this.reporter.clear();
|
||||
this.currentTraceContext.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -22,8 +22,7 @@ import java.util.concurrent.atomic.AtomicReference;
|
||||
import brave.Span;
|
||||
import brave.Tracer;
|
||||
import brave.Tracing;
|
||||
import brave.propagation.StrictScopeDecorator;
|
||||
import brave.propagation.ThreadLocalCurrentTraceContext;
|
||||
import brave.propagation.StrictCurrentTraceContext;
|
||||
import brave.sampler.Sampler;
|
||||
import com.netflix.hystrix.HystrixCommand;
|
||||
import com.netflix.hystrix.HystrixCommandKey;
|
||||
@@ -31,6 +30,7 @@ import com.netflix.hystrix.HystrixCommandProperties;
|
||||
import com.netflix.hystrix.HystrixThreadPoolProperties;
|
||||
import com.netflix.hystrix.strategy.HystrixPlugins;
|
||||
import org.assertj.core.api.BDDAssertions;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -42,11 +42,11 @@ import static org.assertj.core.api.BDDAssertions.then;
|
||||
|
||||
public class TraceCommandTests {
|
||||
|
||||
StrictCurrentTraceContext currentTraceContext = StrictCurrentTraceContext.create();
|
||||
|
||||
ArrayListSpanReporter reporter = new ArrayListSpanReporter();
|
||||
|
||||
Tracing tracing = Tracing.newBuilder()
|
||||
.currentTraceContext(ThreadLocalCurrentTraceContext.newBuilder()
|
||||
.addScopeDecorator(StrictScopeDecorator.create()).build())
|
||||
Tracing tracing = Tracing.newBuilder().currentTraceContext(currentTraceContext)
|
||||
.spanReporter(this.reporter).sampler(Sampler.ALWAYS_SAMPLE).build();
|
||||
|
||||
Tracer tracer = this.tracing.tracer();
|
||||
@@ -57,6 +57,12 @@ public class TraceCommandTests {
|
||||
this.reporter.clear();
|
||||
}
|
||||
|
||||
@After
|
||||
public void close() {
|
||||
this.tracing.close();
|
||||
this.currentTraceContext.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_remove_span_from_thread_local_after_finishing_work()
|
||||
throws Exception {
|
||||
|
||||
@@ -26,8 +26,7 @@ import javax.annotation.PreDestroy;
|
||||
import brave.Span;
|
||||
import brave.Tracer;
|
||||
import brave.Tracing;
|
||||
import brave.propagation.StrictScopeDecorator;
|
||||
import brave.propagation.ThreadLocalCurrentTraceContext;
|
||||
import brave.propagation.StrictCurrentTraceContext;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -153,11 +152,14 @@ public class ITTracingChannelInterceptorTests implements MessageHandler {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
@Bean
|
||||
StrictCurrentTraceContext currentTraceContext() {
|
||||
return StrictCurrentTraceContext.create();
|
||||
}
|
||||
|
||||
@Bean
|
||||
Tracing tracing() {
|
||||
return Tracing.newBuilder()
|
||||
.currentTraceContext(ThreadLocalCurrentTraceContext.newBuilder()
|
||||
.addScopeDecorator(StrictScopeDecorator.create()).build())
|
||||
return Tracing.newBuilder().currentTraceContext(currentTraceContext())
|
||||
.spanReporter(spans()::add).build();
|
||||
}
|
||||
|
||||
|
||||
@@ -23,8 +23,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import brave.Tracing;
|
||||
import brave.propagation.StrictScopeDecorator;
|
||||
import brave.propagation.ThreadLocalCurrentTraceContext;
|
||||
import brave.propagation.StrictCurrentTraceContext;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
import zipkin2.Span;
|
||||
@@ -49,12 +48,14 @@ import static org.springframework.messaging.support.NativeMessageHeaderAccessor.
|
||||
|
||||
public class TracingChannelInterceptorTest {
|
||||
|
||||
StrictCurrentTraceContext currentTraceContext = StrictCurrentTraceContext.create();
|
||||
|
||||
List<Span> spans = new ArrayList<>();
|
||||
|
||||
ChannelInterceptor interceptor = TracingChannelInterceptor.create(Tracing.newBuilder()
|
||||
.currentTraceContext(ThreadLocalCurrentTraceContext.newBuilder()
|
||||
.addScopeDecorator(StrictScopeDecorator.create()).build())
|
||||
.spanReporter(this.spans::add).build());
|
||||
Tracing tracing = Tracing.newBuilder().currentTraceContext(this.currentTraceContext)
|
||||
.spanReporter(this.spans::add).build();
|
||||
|
||||
ChannelInterceptor interceptor = TracingChannelInterceptor.create(tracing);
|
||||
|
||||
QueueChannel channel = new QueueChannel();
|
||||
|
||||
@@ -69,6 +70,12 @@ public class TracingChannelInterceptorTest {
|
||||
}
|
||||
};
|
||||
|
||||
@After
|
||||
public void close() {
|
||||
this.tracing.close();
|
||||
this.currentTraceContext.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pollingReceive_emptyQueue() {
|
||||
this.channel.addInterceptor(consumerSideOnly(this.interceptor));
|
||||
@@ -357,10 +364,4 @@ public class TracingChannelInterceptorTest {
|
||||
return new ExecutorSideOnly();
|
||||
}
|
||||
|
||||
@After
|
||||
public void close() {
|
||||
assertThat(Tracing.current().currentTraceContext().get()).isNull();
|
||||
Tracing.current().close();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -28,8 +28,7 @@ import java.util.concurrent.ThreadFactory;
|
||||
|
||||
import brave.Tracer;
|
||||
import brave.Tracing;
|
||||
import brave.propagation.StrictScopeDecorator;
|
||||
import brave.propagation.ThreadLocalCurrentTraceContext;
|
||||
import brave.propagation.StrictCurrentTraceContext;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -52,11 +51,11 @@ public class SleuthRxJavaSchedulersHookTests {
|
||||
|
||||
List<String> threadsToIgnore = new ArrayList<>();
|
||||
|
||||
StrictCurrentTraceContext currentTraceContext = StrictCurrentTraceContext.create();
|
||||
|
||||
ArrayListSpanReporter reporter = new ArrayListSpanReporter();
|
||||
|
||||
Tracing tracing = Tracing.newBuilder()
|
||||
.currentTraceContext(ThreadLocalCurrentTraceContext.newBuilder()
|
||||
.addScopeDecorator(StrictScopeDecorator.create()).build())
|
||||
Tracing tracing = Tracing.newBuilder().currentTraceContext(this.currentTraceContext)
|
||||
.spanReporter(this.reporter).build();
|
||||
|
||||
Tracer tracer = this.tracing.tracer();
|
||||
@@ -65,6 +64,7 @@ public class SleuthRxJavaSchedulersHookTests {
|
||||
public void clean() {
|
||||
this.tracing.close();
|
||||
this.reporter.clear();
|
||||
this.currentTraceContext.close();
|
||||
}
|
||||
|
||||
@Before
|
||||
|
||||
@@ -23,6 +23,7 @@ import java.util.Map;
|
||||
|
||||
import brave.SpanCustomizer;
|
||||
import brave.http.HttpClientAdapter;
|
||||
import brave.propagation.TraceContext;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
@@ -34,6 +35,8 @@ import static org.assertj.core.api.BDDAssertions.then;
|
||||
*/
|
||||
public class SleuthHttpClientParserTests {
|
||||
|
||||
private TraceContext context = TraceContext.newBuilder().traceId(1).spanId(2).build();
|
||||
|
||||
private TraceKeys traceKeys = new TraceKeys();
|
||||
|
||||
private TestSpanCustomizer customizer = new TestSpanCustomizer();
|
||||
@@ -73,7 +76,7 @@ public class SleuthHttpClientParserTests {
|
||||
public Integer statusCode(Object response) {
|
||||
return 200;
|
||||
}
|
||||
}, null, this.customizer);
|
||||
}, context, this.customizer);
|
||||
|
||||
then(this.customizer.tags).containsEntry("http.user-agent", "Test")
|
||||
.containsEntry("http.accept", "'text/plain','text/xml'")
|
||||
|
||||
@@ -26,8 +26,7 @@ import brave.Span;
|
||||
import brave.Tracer;
|
||||
import brave.Tracing;
|
||||
import brave.http.HttpTracing;
|
||||
import brave.propagation.StrictScopeDecorator;
|
||||
import brave.propagation.ThreadLocalCurrentTraceContext;
|
||||
import brave.propagation.StrictCurrentTraceContext;
|
||||
import brave.sampler.Sampler;
|
||||
import brave.servlet.TracingFilter;
|
||||
import org.junit.After;
|
||||
@@ -61,11 +60,11 @@ public class TraceFilterTests {
|
||||
static final String SAMPLED_ID_NAME = "X-B3-Sampled";
|
||||
static final String SPAN_FLAGS = "X-B3-Flags";
|
||||
|
||||
StrictCurrentTraceContext currentTraceContext = StrictCurrentTraceContext.create();
|
||||
|
||||
ArrayListSpanReporter reporter = new ArrayListSpanReporter();
|
||||
|
||||
Tracing tracing = Tracing.newBuilder()
|
||||
.currentTraceContext(ThreadLocalCurrentTraceContext.newBuilder()
|
||||
.addScopeDecorator(StrictScopeDecorator.create()).build())
|
||||
Tracing tracing = Tracing.newBuilder().currentTraceContext(this.currentTraceContext)
|
||||
.spanReporter(this.reporter).build();
|
||||
|
||||
Tracer tracer = this.tracing.tracer();
|
||||
@@ -101,7 +100,8 @@ public class TraceFilterTests {
|
||||
|
||||
@After
|
||||
public void cleanup() {
|
||||
Tracing.current().close();
|
||||
this.tracing.close();
|
||||
this.currentTraceContext.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -111,14 +111,13 @@ public class TraceFilterTests {
|
||||
|
||||
neverSampleFilter().doFilter(this.request, this.response, this.filterChain);
|
||||
|
||||
then(Tracing.current().tracer().currentSpan()).isNull();
|
||||
then(this.currentTraceContext.get()).isNull();
|
||||
then(this.reporter.getSpans()).isEmpty();
|
||||
}
|
||||
|
||||
private Filter neverSampleFilter() {
|
||||
Tracing tracing = Tracing.newBuilder()
|
||||
.currentTraceContext(ThreadLocalCurrentTraceContext.newBuilder()
|
||||
.addScopeDecorator(StrictScopeDecorator.create()).build())
|
||||
this.tracing.close();
|
||||
this.tracing = Tracing.newBuilder().currentTraceContext(this.currentTraceContext)
|
||||
.spanReporter(this.reporter).sampler(Sampler.NEVER_SAMPLE)
|
||||
.supportsJoin(false).build();
|
||||
HttpTracing httpTracing = HttpTracing.newBuilder(tracing)
|
||||
@@ -150,7 +149,7 @@ public class TraceFilterTests {
|
||||
this.response.setStatus(0);
|
||||
this.filter.doFilter(this.request, this.response, this.filterChain);
|
||||
|
||||
then(Tracing.current().tracer().currentSpan()).isNull();
|
||||
then(this.currentTraceContext.get()).isNull();
|
||||
then(this.reporter.getSpans()).hasSize(1);
|
||||
then(this.reporter.getSpans().get(0).tags())
|
||||
.doesNotContainKey("http.status_code");
|
||||
@@ -165,7 +164,7 @@ public class TraceFilterTests {
|
||||
|
||||
this.filter.doFilter(this.request, this.response, this.filterChain);
|
||||
|
||||
then(Tracing.current().tracer().currentSpan()).isNull();
|
||||
then(this.currentTraceContext.get()).isNull();
|
||||
then(this.reporter.getSpans()).hasSize(1);
|
||||
then(this.reporter.getSpans().get(0).id()).isEqualTo(PARENT_ID);
|
||||
then(this.reporter.getSpans().get(0).tags())
|
||||
@@ -187,7 +186,7 @@ public class TraceFilterTests {
|
||||
span.set(this.tracing.tracer().currentSpan());
|
||||
});
|
||||
|
||||
then(Tracing.current().tracer().currentSpan()).isNull();
|
||||
then(this.currentTraceContext.get()).isNull();
|
||||
then(span.get().context().traceIdString()).isEqualTo(SpanUtil.idToHex(2L));
|
||||
}
|
||||
|
||||
@@ -197,7 +196,7 @@ public class TraceFilterTests {
|
||||
|
||||
this.filter.doFilter(this.request, this.response, this.filterChain);
|
||||
|
||||
then(Tracing.current().tracer().currentSpan()).isNull();
|
||||
then(this.currentTraceContext.get()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -207,7 +206,7 @@ public class TraceFilterTests {
|
||||
|
||||
this.filter.doFilter(this.request, this.response, this.filterChain);
|
||||
|
||||
then(Tracing.current().tracer().currentSpan()).isNull();
|
||||
then(this.currentTraceContext.get()).isNull();
|
||||
then(this.reporter.getSpans()).hasSize(1);
|
||||
}
|
||||
|
||||
@@ -217,7 +216,7 @@ public class TraceFilterTests {
|
||||
Span span = this.tracer.nextSpan().name("http:foo");
|
||||
this.response.setStatus(404);
|
||||
|
||||
then(Tracing.current().tracer().currentSpan()).isNull();
|
||||
then(this.currentTraceContext.get()).isNull();
|
||||
this.filter.doFilter(this.request, this.response, this.filterChain);
|
||||
}
|
||||
|
||||
@@ -229,15 +228,14 @@ public class TraceFilterTests {
|
||||
|
||||
this.filter.doFilter(this.request, this.response, this.filterChain);
|
||||
|
||||
then(Tracing.current().tracer().currentSpan()).isNull();
|
||||
then(this.currentTraceContext.get()).isNull();
|
||||
verifyParentSpanHttpTags();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createsChildFromHeadersWhenJoinUnsupported() throws Exception {
|
||||
Tracing tracing = Tracing.newBuilder()
|
||||
.currentTraceContext(ThreadLocalCurrentTraceContext.newBuilder()
|
||||
.addScopeDecorator(StrictScopeDecorator.create()).build())
|
||||
this.tracing.close();
|
||||
this.tracing = Tracing.newBuilder().currentTraceContext(this.currentTraceContext)
|
||||
.spanReporter(this.reporter).supportsJoin(false).build();
|
||||
HttpTracing httpTracing = HttpTracing.create(tracing);
|
||||
this.request = builder().header(SPAN_ID_NAME, PARENT_ID)
|
||||
@@ -247,7 +245,7 @@ public class TraceFilterTests {
|
||||
TracingFilter.create(httpTracing).doFilter(this.request, this.response,
|
||||
this.filterChain);
|
||||
|
||||
then(Tracing.current().tracer().currentSpan()).isNull();
|
||||
then(this.currentTraceContext.get()).isNull();
|
||||
then(this.reporter.getSpans()).hasSize(1);
|
||||
then(this.reporter.getSpans().get(0).parentId()).isEqualTo(PARENT_ID);
|
||||
}
|
||||
@@ -262,7 +260,7 @@ public class TraceFilterTests {
|
||||
|
||||
this.filter.doFilter(this.request, this.response, this.filterChain);
|
||||
|
||||
then(Tracing.current().tracer().currentSpan()).isNull();
|
||||
then(this.currentTraceContext.get()).isNull();
|
||||
then(this.reporter.getSpans()).hasSize(1);
|
||||
then(this.reporter.getSpans().get(0).tags()).containsEntry("http.x-foo", "bar");
|
||||
}
|
||||
@@ -277,7 +275,7 @@ public class TraceFilterTests {
|
||||
this.request.addHeader("X-Foo", "spam");
|
||||
this.filter.doFilter(this.request, this.response, this.filterChain);
|
||||
|
||||
then(Tracing.current().tracer().currentSpan()).isNull();
|
||||
then(this.currentTraceContext.get()).isNull();
|
||||
then(this.reporter.getSpans()).hasSize(1);
|
||||
// We no longer support multi value headers
|
||||
then(this.reporter.getSpans().get(0).tags()).containsEntry("http.x-foo", "bar");
|
||||
@@ -304,7 +302,7 @@ public class TraceFilterTests {
|
||||
assertThat(e.getMessage()).isEqualTo("Planned");
|
||||
}
|
||||
|
||||
then(Tracing.current().tracer().currentSpan()).isNull();
|
||||
then(this.currentTraceContext.get()).isNull();
|
||||
verifyParentSpanHttpTags(HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
then(this.reporter.getSpans()).hasSize(1);
|
||||
then(this.reporter.getSpans().get(0).tags()).containsEntry("error", "Planned");
|
||||
@@ -318,7 +316,7 @@ public class TraceFilterTests {
|
||||
|
||||
this.response.setStatus(404);
|
||||
|
||||
then(Tracing.current().tracer().currentSpan()).isNull();
|
||||
then(this.currentTraceContext.get()).isNull();
|
||||
this.filter.doFilter(this.request, this.response, this.filterChain);
|
||||
}
|
||||
|
||||
@@ -331,7 +329,7 @@ public class TraceFilterTests {
|
||||
|
||||
this.filter.doFilter(this.request, this.response, this.filterChain);
|
||||
|
||||
then(Tracing.current().tracer().currentSpan()).isNull();
|
||||
then(this.currentTraceContext.get()).isNull();
|
||||
then(this.reporter.getSpans()).hasSize(1);
|
||||
}
|
||||
|
||||
@@ -344,7 +342,7 @@ public class TraceFilterTests {
|
||||
|
||||
this.filter.doFilter(this.request, this.response, this.filterChain);
|
||||
|
||||
then(Tracing.current().tracer().currentSpan()).isNull();
|
||||
then(this.currentTraceContext.get()).isNull();
|
||||
then(this.reporter.getSpans()).hasSize(1);
|
||||
}
|
||||
|
||||
@@ -356,7 +354,7 @@ public class TraceFilterTests {
|
||||
|
||||
this.filter.doFilter(this.request, this.response, this.filterChain);
|
||||
|
||||
then(Tracing.current().tracer().currentSpan()).isNull();
|
||||
then(this.currentTraceContext.get()).isNull();
|
||||
then(this.reporter.getSpans()).isNotEmpty();
|
||||
then(this.response.getStatus()).isEqualTo(HttpStatus.OK.value());
|
||||
}
|
||||
@@ -370,7 +368,7 @@ public class TraceFilterTests {
|
||||
|
||||
this.filter.doFilter(this.request, this.response, this.filterChain);
|
||||
|
||||
then(Tracing.current().tracer().currentSpan()).isNull();
|
||||
then(this.currentTraceContext.get()).isNull();
|
||||
then(this.reporter.getSpans()).isNotEmpty();
|
||||
then(this.response.getStatus()).isEqualTo(HttpStatus.OK.value());
|
||||
}
|
||||
@@ -383,7 +381,7 @@ public class TraceFilterTests {
|
||||
|
||||
neverSampleFilter().doFilter(this.request, this.response, this.filterChain);
|
||||
|
||||
then(Tracing.current().tracer().currentSpan()).isNull();
|
||||
then(this.currentTraceContext.get()).isNull();
|
||||
then(this.reporter.getSpans()).isNotEmpty();
|
||||
}
|
||||
|
||||
@@ -395,7 +393,7 @@ public class TraceFilterTests {
|
||||
|
||||
this.filter.doFilter(this.request, this.response, this.filterChain);
|
||||
|
||||
then(Tracing.current().tracer().currentSpan()).isNull();
|
||||
then(this.currentTraceContext.get()).isNull();
|
||||
then(this.reporter.getSpans()).isNotEmpty();
|
||||
}
|
||||
|
||||
@@ -408,7 +406,7 @@ public class TraceFilterTests {
|
||||
|
||||
neverSampleFilter().doFilter(this.request, this.response, this.filterChain);
|
||||
|
||||
then(Tracing.current().tracer().currentSpan()).isNull();
|
||||
then(this.currentTraceContext.get()).isNull();
|
||||
// It is ok to go without a trace ID, if sampling or debug is set
|
||||
then(this.reporter.getSpans()).hasSize(1).extracting("id")
|
||||
.isNotEqualTo(SpanUtil.idToHex(10L));
|
||||
@@ -423,7 +421,7 @@ public class TraceFilterTests {
|
||||
|
||||
neverSampleFilter().doFilter(this.request, this.response, this.filterChain);
|
||||
|
||||
then(Tracing.current().tracer().currentSpan()).isNull();
|
||||
then(this.currentTraceContext.get()).isNull();
|
||||
then(this.reporter.getSpans()).isEmpty();
|
||||
}
|
||||
|
||||
@@ -436,7 +434,7 @@ public class TraceFilterTests {
|
||||
|
||||
this.filter.doFilter(this.request, this.response, this.filterChain);
|
||||
|
||||
then(Tracing.current().tracer().currentSpan()).isNull();
|
||||
then(this.currentTraceContext.get()).isNull();
|
||||
then(this.reporter.getSpans()).hasSize(1);
|
||||
then(this.reporter.getSpans().get(0).tags())
|
||||
.containsEntry("http.url", "http://localhost/?foo=bar")
|
||||
@@ -453,7 +451,7 @@ public class TraceFilterTests {
|
||||
|
||||
neverSampleFilter().doFilter(this.request, this.response, this.filterChain);
|
||||
|
||||
then(Tracing.current().tracer().currentSpan()).isNull();
|
||||
then(this.currentTraceContext.get()).isNull();
|
||||
then(this.reporter.getSpans()).hasSize(1);
|
||||
then(this.reporter.getSpans().get(0).name()).isEqualTo("http:/");
|
||||
}
|
||||
|
||||
@@ -22,8 +22,8 @@ import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import brave.Tracing;
|
||||
import brave.http.HttpRequest;
|
||||
import brave.propagation.CurrentTraceContext;
|
||||
import brave.sampler.Sampler;
|
||||
import brave.sampler.SamplerFunction;
|
||||
import org.assertj.core.api.BDDAssertions;
|
||||
@@ -66,10 +66,10 @@ public class TraceFilterWebIntegrationTests {
|
||||
public OutputCapture capture = new OutputCapture();
|
||||
|
||||
@Autowired
|
||||
Tracing tracer;
|
||||
ArrayListSpanReporter accumulator;
|
||||
|
||||
@Autowired
|
||||
ArrayListSpanReporter accumulator;
|
||||
CurrentTraceContext currentTraceContext;
|
||||
|
||||
@Autowired
|
||||
@HttpServerSampler
|
||||
@@ -94,7 +94,7 @@ public class TraceFilterWebIntegrationTests {
|
||||
catch (Exception e) {
|
||||
}
|
||||
|
||||
then(Tracing.current().tracer().currentSpan()).isNull();
|
||||
then(this.currentTraceContext.get()).isNull();
|
||||
then(this.accumulator.getSpans()).hasSize(1);
|
||||
Span fromFirstTraceFilterFlow = this.accumulator.getSpans().get(0);
|
||||
then(fromFirstTraceFilterFlow.tags()).containsEntry("http.status_code", "500")
|
||||
@@ -122,7 +122,7 @@ public class TraceFilterWebIntegrationTests {
|
||||
catch (HttpClientErrorException e) {
|
||||
}
|
||||
|
||||
then(Tracing.current().tracer().currentSpan()).isNull();
|
||||
then(this.currentTraceContext.get()).isNull();
|
||||
then(this.accumulator.getSpans()).hasSize(1);
|
||||
then(this.accumulator.getSpans().get(0).kind().ordinal())
|
||||
.isEqualTo(Span.Kind.SERVER.ordinal());
|
||||
|
||||
@@ -25,8 +25,7 @@ import brave.Span;
|
||||
import brave.Tracer;
|
||||
import brave.Tracing;
|
||||
import brave.http.HttpTracing;
|
||||
import brave.propagation.StrictScopeDecorator;
|
||||
import brave.propagation.ThreadLocalCurrentTraceContext;
|
||||
import brave.propagation.StrictCurrentTraceContext;
|
||||
import brave.sampler.Sampler;
|
||||
import brave.spring.web.TracingClientHttpRequestInterceptor;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@@ -55,11 +54,11 @@ import static org.assertj.core.api.BDDAssertions.then;
|
||||
*/
|
||||
public class TraceRestTemplateInterceptorTests {
|
||||
|
||||
StrictCurrentTraceContext currentTraceContext = StrictCurrentTraceContext.create();
|
||||
|
||||
ArrayListSpanReporter reporter = new ArrayListSpanReporter();
|
||||
|
||||
Tracing tracing = Tracing.newBuilder()
|
||||
.currentTraceContext(ThreadLocalCurrentTraceContext.newBuilder()
|
||||
.addScopeDecorator(StrictScopeDecorator.create()).build())
|
||||
Tracing tracing = Tracing.newBuilder().currentTraceContext(this.currentTraceContext)
|
||||
.spanReporter(this.reporter).build();
|
||||
|
||||
Tracer tracer = this.tracing.tracer();
|
||||
@@ -86,7 +85,8 @@ public class TraceRestTemplateInterceptorTests {
|
||||
|
||||
@After
|
||||
public void clean() {
|
||||
Tracing.current().close();
|
||||
this.tracing.close();
|
||||
this.currentTraceContext.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -141,9 +141,8 @@ public class TraceRestTemplateInterceptorTests {
|
||||
|
||||
@Test
|
||||
public void notSampledHeaderAddedWhenNotExportable() {
|
||||
Tracing tracing = Tracing.newBuilder()
|
||||
.currentTraceContext(ThreadLocalCurrentTraceContext.newBuilder()
|
||||
.addScopeDecorator(StrictScopeDecorator.create()).build())
|
||||
this.tracing.close();
|
||||
this.tracing = Tracing.newBuilder().currentTraceContext(this.currentTraceContext)
|
||||
.spanReporter(this.reporter).sampler(Sampler.NEVER_SAMPLE).build();
|
||||
this.template.setInterceptors(Arrays.<ClientHttpRequestInterceptor>asList(
|
||||
TracingClientHttpRequestInterceptor.create(HttpTracing.create(tracing))));
|
||||
|
||||
@@ -22,6 +22,7 @@ import java.util.concurrent.ExecutionException;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import brave.Tracing;
|
||||
import brave.propagation.CurrentTraceContext;
|
||||
import brave.sampler.Sampler;
|
||||
import brave.spring.web.TracingAsyncClientHttpRequestInterceptor;
|
||||
import org.junit.After;
|
||||
@@ -72,6 +73,9 @@ public class RestTemplateTraceAspectIntegrationTests {
|
||||
@Autowired
|
||||
AspectTestingController controller;
|
||||
|
||||
@Autowired
|
||||
CurrentTraceContext currentTraceContext;
|
||||
|
||||
@Autowired
|
||||
Tracing tracer;
|
||||
|
||||
@@ -138,7 +142,7 @@ public class RestTemplateTraceAspectIntegrationTests {
|
||||
throws Exception {
|
||||
whenARequestIsSentToASyncEndpointThatShouldBeFilteredOut();
|
||||
|
||||
then(Tracing.current().tracer().currentSpan()).isNull();
|
||||
then(this.currentTraceContext.get()).isNull();
|
||||
then(this.reporter.getSpans()).isEmpty();
|
||||
}
|
||||
|
||||
|
||||
@@ -21,9 +21,9 @@ import java.util.Collections;
|
||||
|
||||
import brave.Tracing;
|
||||
import brave.http.HttpTracing;
|
||||
import brave.propagation.StrictScopeDecorator;
|
||||
import brave.propagation.ThreadLocalCurrentTraceContext;
|
||||
import brave.propagation.StrictCurrentTraceContext;
|
||||
import org.assertj.core.api.BDDAssertions;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.cloud.gateway.filter.headers.HttpHeadersFilter;
|
||||
@@ -34,15 +34,21 @@ import org.springframework.mock.web.server.MockServerWebExchange;
|
||||
|
||||
public class TraceRequestHttpHeadersFilterTests {
|
||||
|
||||
StrictCurrentTraceContext currentTraceContext = StrictCurrentTraceContext.create();
|
||||
|
||||
ArrayListSpanReporter reporter = new ArrayListSpanReporter();
|
||||
|
||||
Tracing tracing = Tracing.newBuilder()
|
||||
.currentTraceContext(ThreadLocalCurrentTraceContext.newBuilder()
|
||||
.addScopeDecorator(StrictScopeDecorator.create()).build())
|
||||
Tracing tracing = Tracing.newBuilder().currentTraceContext(this.currentTraceContext)
|
||||
.spanReporter(this.reporter).build();
|
||||
|
||||
HttpTracing httpTracing = HttpTracing.newBuilder(this.tracing).build();
|
||||
|
||||
@After
|
||||
public void close() {
|
||||
this.tracing.close();
|
||||
this.currentTraceContext.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_override_span_tracing_headers() {
|
||||
HttpHeadersFilter filter = TraceRequestHttpHeadersFilter.create(this.httpTracing);
|
||||
|
||||
@@ -18,9 +18,9 @@ package org.springframework.cloud.sleuth.instrument.web.client;
|
||||
|
||||
import brave.Tracing;
|
||||
import brave.http.HttpTracing;
|
||||
import brave.propagation.StrictScopeDecorator;
|
||||
import brave.propagation.ThreadLocalCurrentTraceContext;
|
||||
import brave.propagation.StrictCurrentTraceContext;
|
||||
import org.assertj.core.api.BDDAssertions;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.cloud.gateway.filter.headers.HttpHeadersFilter;
|
||||
@@ -31,15 +31,21 @@ import org.springframework.mock.web.server.MockServerWebExchange;
|
||||
|
||||
public class TraceResponseHttpHeadersFilterTests {
|
||||
|
||||
StrictCurrentTraceContext currentTraceContext = StrictCurrentTraceContext.create();
|
||||
|
||||
ArrayListSpanReporter reporter = new ArrayListSpanReporter();
|
||||
|
||||
Tracing tracing = Tracing.newBuilder()
|
||||
.currentTraceContext(ThreadLocalCurrentTraceContext.newBuilder()
|
||||
.addScopeDecorator(StrictScopeDecorator.create()).build())
|
||||
Tracing tracing = Tracing.newBuilder().currentTraceContext(this.currentTraceContext)
|
||||
.spanReporter(this.reporter).build();
|
||||
|
||||
HttpTracing httpTracing = HttpTracing.newBuilder(this.tracing).build();
|
||||
|
||||
@After
|
||||
public void close() {
|
||||
this.tracing.close();
|
||||
this.currentTraceContext.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_not_report_span_when_no_span_was_present_in_attribute() {
|
||||
HttpHeadersFilter filter = TraceResponseHttpHeadersFilter
|
||||
|
||||
@@ -24,8 +24,7 @@ import brave.Span;
|
||||
import brave.Tracer;
|
||||
import brave.Tracing;
|
||||
import brave.http.HttpTracing;
|
||||
import brave.propagation.StrictScopeDecorator;
|
||||
import brave.propagation.ThreadLocalCurrentTraceContext;
|
||||
import brave.propagation.StrictCurrentTraceContext;
|
||||
import brave.spring.web.TracingClientHttpRequestInterceptor;
|
||||
import okhttp3.mockwebserver.MockResponse;
|
||||
import okhttp3.mockwebserver.MockWebServer;
|
||||
@@ -52,11 +51,11 @@ public class TraceRestTemplateInterceptorIntegrationTests {
|
||||
@Rule
|
||||
public final MockWebServer mockWebServer = new MockWebServer();
|
||||
|
||||
StrictCurrentTraceContext currentTraceContext = StrictCurrentTraceContext.create();
|
||||
|
||||
ArrayListSpanReporter reporter = new ArrayListSpanReporter();
|
||||
|
||||
Tracing tracing = Tracing.newBuilder()
|
||||
.currentTraceContext(ThreadLocalCurrentTraceContext.newBuilder()
|
||||
.addScopeDecorator(StrictScopeDecorator.create()).build())
|
||||
Tracing tracing = Tracing.newBuilder().currentTraceContext(this.currentTraceContext)
|
||||
.spanReporter(this.reporter).build();
|
||||
|
||||
Tracer tracer = this.tracing.tracer();
|
||||
@@ -72,7 +71,8 @@ public class TraceRestTemplateInterceptorIntegrationTests {
|
||||
|
||||
@After
|
||||
public void clean() {
|
||||
Tracing.current().close();
|
||||
this.tracing.close();
|
||||
this.currentTraceContext.close();
|
||||
}
|
||||
|
||||
// Issue #198
|
||||
|
||||
@@ -22,6 +22,7 @@ import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import brave.Span;
|
||||
import brave.Tracing;
|
||||
import brave.propagation.CurrentTraceContext;
|
||||
import brave.sampler.Sampler;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import org.junit.Test;
|
||||
@@ -55,6 +56,9 @@ public class Issue585Tests {
|
||||
|
||||
TestRestTemplate testRestTemplate = new TestRestTemplate();
|
||||
|
||||
@Autowired
|
||||
CurrentTraceContext currentTraceContext;
|
||||
|
||||
@Autowired
|
||||
ArrayListSpanReporter reporter;
|
||||
|
||||
@@ -67,7 +71,7 @@ public class Issue585Tests {
|
||||
"http://localhost:" + this.port + "/sleuthtest?greeting=foo",
|
||||
String.class);
|
||||
|
||||
then(Tracing.current().tracer().currentSpan()).isNull();
|
||||
then(this.currentTraceContext.get()).isNull();
|
||||
then(entity.getStatusCode().value()).isEqualTo(500);
|
||||
then(this.reporter.getSpans().get(0).tags()).containsEntry("custom", "tag")
|
||||
.containsKeys("error");
|
||||
|
||||
@@ -23,8 +23,7 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import brave.Tracing;
|
||||
import brave.http.HttpTracing;
|
||||
import brave.propagation.StrictScopeDecorator;
|
||||
import brave.propagation.ThreadLocalCurrentTraceContext;
|
||||
import brave.propagation.StrictCurrentTraceContext;
|
||||
import feign.Client;
|
||||
import feign.Feign;
|
||||
import feign.FeignException;
|
||||
@@ -61,11 +60,11 @@ public class FeignRetriesTests {
|
||||
@Mock
|
||||
BeanFactory beanFactory;
|
||||
|
||||
StrictCurrentTraceContext currentTraceContext = StrictCurrentTraceContext.create();
|
||||
|
||||
ArrayListSpanReporter reporter = new ArrayListSpanReporter();
|
||||
|
||||
Tracing tracing = Tracing.newBuilder()
|
||||
.currentTraceContext(ThreadLocalCurrentTraceContext.newBuilder()
|
||||
.addScopeDecorator(StrictScopeDecorator.create()).build())
|
||||
Tracing tracing = Tracing.newBuilder().currentTraceContext(this.currentTraceContext)
|
||||
.spanReporter(this.reporter).build();
|
||||
|
||||
HttpTracing httpTracing = HttpTracing.newBuilder(this.tracing)
|
||||
@@ -78,6 +77,12 @@ public class FeignRetriesTests {
|
||||
.willReturn(this.httpTracing);
|
||||
}
|
||||
|
||||
@After
|
||||
public void close() {
|
||||
this.tracing.close();
|
||||
this.currentTraceContext.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRetriedWhenExceededNumberOfRetries() throws Exception {
|
||||
Client client = (request, options) -> {
|
||||
|
||||
@@ -16,14 +16,12 @@
|
||||
|
||||
package org.springframework.cloud.sleuth.instrument.web.client.feign;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import brave.Tracing;
|
||||
import brave.http.HttpTracing;
|
||||
import brave.propagation.StrictScopeDecorator;
|
||||
import brave.propagation.ThreadLocalCurrentTraceContext;
|
||||
import brave.propagation.StrictCurrentTraceContext;
|
||||
import feign.Client;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -55,9 +53,9 @@ public class TraceFeignAspectTests {
|
||||
@Mock
|
||||
TraceLoadBalancerFeignClient traceLoadBalancerFeignClient;
|
||||
|
||||
Tracing tracing = Tracing.newBuilder()
|
||||
.currentTraceContext(ThreadLocalCurrentTraceContext.newBuilder()
|
||||
.addScopeDecorator(StrictScopeDecorator.create()).build())
|
||||
StrictCurrentTraceContext currentTraceContext = StrictCurrentTraceContext.create();
|
||||
|
||||
Tracing tracing = Tracing.newBuilder().currentTraceContext(currentTraceContext)
|
||||
.build();
|
||||
|
||||
HttpTracing httpTracing = HttpTracing.newBuilder(this.tracing)
|
||||
@@ -69,13 +67,18 @@ public class TraceFeignAspectTests {
|
||||
public void setup() {
|
||||
this.traceFeignAspect = new TraceFeignAspect(this.beanFactory) {
|
||||
@Override
|
||||
Object executeTraceFeignClient(Object bean, ProceedingJoinPoint pjp)
|
||||
throws IOException {
|
||||
Object executeTraceFeignClient(Object bean, ProceedingJoinPoint pjp) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@After
|
||||
public void close() {
|
||||
this.tracing.close();
|
||||
this.currentTraceContext.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_wrap_feign_client_in_trace_representation() throws Throwable {
|
||||
given(this.pjp.getTarget()).willReturn(this.client);
|
||||
|
||||
@@ -25,11 +25,11 @@ import brave.Span;
|
||||
import brave.Tracer;
|
||||
import brave.Tracing;
|
||||
import brave.http.HttpTracing;
|
||||
import brave.propagation.StrictScopeDecorator;
|
||||
import brave.propagation.ThreadLocalCurrentTraceContext;
|
||||
import brave.propagation.StrictCurrentTraceContext;
|
||||
import feign.Client;
|
||||
import feign.Request;
|
||||
import org.assertj.core.api.BDDAssertions;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -51,11 +51,11 @@ public class TracingFeignClientTests {
|
||||
|
||||
Request.Options options = new Request.Options();
|
||||
|
||||
StrictCurrentTraceContext currentTraceContext = StrictCurrentTraceContext.create();
|
||||
|
||||
List<zipkin2.Span> spans = new ArrayList<>();
|
||||
|
||||
Tracing tracing = Tracing.newBuilder()
|
||||
.currentTraceContext(ThreadLocalCurrentTraceContext.newBuilder()
|
||||
.addScopeDecorator(StrictScopeDecorator.create()).build())
|
||||
Tracing tracing = Tracing.newBuilder().currentTraceContext(currentTraceContext)
|
||||
.spanReporter(spans::add).build();
|
||||
|
||||
Tracer tracer = this.tracing.tracer();
|
||||
@@ -73,6 +73,12 @@ public class TracingFeignClientTests {
|
||||
this.traceFeignClient = TracingFeignClient.create(this.httpTracing, this.client);
|
||||
}
|
||||
|
||||
@After
|
||||
public void close() {
|
||||
this.tracing.close();
|
||||
this.currentTraceContext.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_log_cr_when_response_successful() throws IOException {
|
||||
Span span = this.tracer.nextSpan().name("foo");
|
||||
|
||||
@@ -16,17 +16,12 @@
|
||||
|
||||
package org.springframework.cloud.sleuth.instrument.web.client.feign;
|
||||
|
||||
import brave.Tracing;
|
||||
import brave.http.HttpTracing;
|
||||
import feign.Client;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
@@ -36,13 +31,6 @@ import static org.mockito.Mockito.mock;
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class TracingFeignObjectWrapperTests {
|
||||
|
||||
Tracing tracing = Tracing.newBuilder().build();
|
||||
|
||||
HttpTracing httpTracing = HttpTracing.create(this.tracing);
|
||||
|
||||
@Mock
|
||||
BeanFactory beanFactory;
|
||||
|
||||
@InjectMocks
|
||||
TraceFeignObjectWrapper traceFeignObjectWrapper;
|
||||
|
||||
|
||||
@@ -21,7 +21,6 @@ import java.nio.charset.Charset;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import brave.Tracing;
|
||||
import brave.sampler.Sampler;
|
||||
import feign.Client;
|
||||
import feign.Request;
|
||||
@@ -71,9 +70,6 @@ public class Issue502Tests {
|
||||
@Autowired
|
||||
ArrayListSpanReporter reporter;
|
||||
|
||||
@Autowired
|
||||
Tracing tracer;
|
||||
|
||||
@Before
|
||||
public void open() {
|
||||
this.reporter.clear();
|
||||
|
||||
@@ -26,8 +26,7 @@ import brave.Span;
|
||||
import brave.Tracer;
|
||||
import brave.Tracing;
|
||||
import brave.http.HttpTracing;
|
||||
import brave.propagation.StrictScopeDecorator;
|
||||
import brave.propagation.ThreadLocalCurrentTraceContext;
|
||||
import brave.propagation.StrictCurrentTraceContext;
|
||||
import com.netflix.zuul.context.RequestContext;
|
||||
import com.netflix.zuul.monitoring.TracerFactory;
|
||||
import org.junit.After;
|
||||
@@ -57,11 +56,11 @@ public class TracePostZuulFilterTests {
|
||||
@Mock
|
||||
HttpServletResponse httpServletResponse;
|
||||
|
||||
StrictCurrentTraceContext currentTraceContext = StrictCurrentTraceContext.create();
|
||||
|
||||
ArrayListSpanReporter reporter = new ArrayListSpanReporter();
|
||||
|
||||
Tracing tracing = Tracing.newBuilder()
|
||||
.currentTraceContext(ThreadLocalCurrentTraceContext.newBuilder()
|
||||
.addScopeDecorator(StrictScopeDecorator.create()).build())
|
||||
Tracing tracing = Tracing.newBuilder().currentTraceContext(this.currentTraceContext)
|
||||
.spanReporter(this.reporter).build();
|
||||
|
||||
HttpTracing httpTracing = HttpTracing.newBuilder(this.tracing)
|
||||
@@ -75,7 +74,8 @@ public class TracePostZuulFilterTests {
|
||||
@After
|
||||
public void clean() {
|
||||
RequestContext.getCurrentContext().unset();
|
||||
this.httpTracing.tracing().close();
|
||||
this.tracing.close();
|
||||
this.currentTraceContext.close();
|
||||
RequestContext.testSetCurrentContext(null);
|
||||
}
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
<name>spring-cloud-sleuth-dependencies</name>
|
||||
<description>Spring Cloud Sleuth Dependencies</description>
|
||||
<properties>
|
||||
<brave.version>5.11.0</brave.version>
|
||||
<brave.opentracing.version>0.33.13</brave.opentracing.version>
|
||||
<grpc.spring.boot.version>3.0.1</grpc.spring.boot.version>
|
||||
</properties>
|
||||
|
||||
@@ -21,7 +21,6 @@ import java.nio.charset.Charset;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import brave.Tracing;
|
||||
import brave.sampler.Sampler;
|
||||
import feign.Client;
|
||||
import feign.Request;
|
||||
@@ -75,9 +74,6 @@ public class IssueXTests {
|
||||
@Autowired
|
||||
ArrayListSpanReporter reporter;
|
||||
|
||||
@Autowired
|
||||
Tracing tracer;
|
||||
|
||||
@Before
|
||||
public void open() {
|
||||
this.reporter.clear();
|
||||
|
||||
Reference in New Issue
Block a user