Updates to latest brave and removes all static thread local use (#1594)
This commit is contained in:
@@ -33,7 +33,7 @@
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<spring-boot.version>2.2.5.RELEASE</spring-boot.version>
|
||||
<brave.version>5.10.2</brave.version>
|
||||
<brave.version>5.11.0</brave.version>
|
||||
<okhttp.version>3.14.6</okhttp.version>
|
||||
</properties>
|
||||
|
||||
|
||||
2
pom.xml
2
pom.xml
@@ -264,7 +264,7 @@
|
||||
<spring-cloud-stream.version>Horsham.SR3</spring-cloud-stream.version>
|
||||
<spring-cloud-netflix.version>2.2.3.BUILD-SNAPSHOT</spring-cloud-netflix.version>
|
||||
<spring-cloud-openfeign.version>2.2.3.BUILD-SNAPSHOT</spring-cloud-openfeign.version>
|
||||
<brave.version>5.10.2</brave.version>
|
||||
<brave.version>5.11.0</brave.version>
|
||||
<spring-security-boot-autoconfigure.version>2.1.7.RELEASE</spring-security-boot-autoconfigure.version>
|
||||
<spring-cloud-aws.version>2.2.1.RELEASE</spring-cloud-aws.version>
|
||||
<disable.nohttp.checks>false</disable.nohttp.checks>
|
||||
|
||||
@@ -219,7 +219,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 {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -22,10 +22,10 @@ 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.sampler.Sampler;
|
||||
import org.assertj.core.api.BDDAssertions;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -36,11 +36,11 @@ import static org.assertj.core.api.BDDAssertions.then;
|
||||
|
||||
public class CircuitBreakerTests {
|
||||
|
||||
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).sampler(Sampler.ALWAYS_SAMPLE).build();
|
||||
|
||||
Tracer tracer = this.tracing.tracer();
|
||||
@@ -50,6 +50,12 @@ public class CircuitBreakerTests {
|
||||
this.reporter.clear();
|
||||
}
|
||||
|
||||
@After
|
||||
public void close() {
|
||||
this.tracing.close();
|
||||
this.currentTraceContext.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_pass_tracing_information_when_using_circuit_breaker() {
|
||||
// given
|
||||
|
||||
@@ -22,8 +22,7 @@ import java.util.concurrent.TimeUnit;
|
||||
|
||||
import brave.Tracing;
|
||||
import brave.propagation.CurrentTraceContext;
|
||||
import brave.propagation.StrictScopeDecorator;
|
||||
import brave.propagation.ThreadLocalCurrentTraceContext;
|
||||
import brave.propagation.StrictCurrentTraceContext;
|
||||
import brave.propagation.TraceContext;
|
||||
import com.netflix.hystrix.HystrixThreadPoolKey;
|
||||
import com.netflix.hystrix.HystrixThreadPoolProperties;
|
||||
@@ -54,9 +53,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
|
||||
@@ -64,6 +63,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 {
|
||||
|
||||
@@ -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;
|
||||
@@ -51,12 +50,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();
|
||||
|
||||
@@ -71,6 +72,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));
|
||||
@@ -424,10 +431,4 @@ public class TracingChannelInterceptorTest {
|
||||
return new ExecutorSideOnly();
|
||||
}
|
||||
|
||||
@After
|
||||
public void close() {
|
||||
assertThat(Tracing.current().currentTraceContext().get()).isNull();
|
||||
Tracing.current().close();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -25,8 +25,7 @@ import java.util.concurrent.CompletableFuture;
|
||||
import brave.Tracer.SpanInScope;
|
||||
import brave.Tracing;
|
||||
import brave.propagation.Propagation.Setter;
|
||||
import brave.propagation.StrictScopeDecorator;
|
||||
import brave.propagation.ThreadLocalCurrentTraceContext;
|
||||
import brave.propagation.StrictCurrentTraceContext;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -68,21 +67,20 @@ public class TracingJobListenerTest {
|
||||
|
||||
private TracingJobListener listener;
|
||||
|
||||
private Tracing tracing;
|
||||
|
||||
private Scheduler scheduler;
|
||||
|
||||
private CompletableFuture completableJob;
|
||||
|
||||
private StrictCurrentTraceContext currentTraceContext = StrictCurrentTraceContext
|
||||
.create();
|
||||
|
||||
private Queue<Span> spans = new ArrayDeque<>();
|
||||
|
||||
private Tracing tracing = Tracing.newBuilder().spanReporter(spans::add)
|
||||
.currentTraceContext(currentTraceContext).build();
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
tracing = Tracing.newBuilder().spanReporter(spans::add)
|
||||
.currentTraceContext(ThreadLocalCurrentTraceContext.newBuilder()
|
||||
.addScopeDecorator(StrictScopeDecorator.create()).build())
|
||||
.build();
|
||||
|
||||
listener = new TracingJobListener(tracing);
|
||||
completableJob = new CompleteableTriggerListener();
|
||||
|
||||
@@ -103,7 +101,9 @@ public class TracingJobListenerTest {
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
scheduler.shutdown(true);
|
||||
this.scheduler.shutdown(true);
|
||||
this.tracing.close();
|
||||
this.currentTraceContext.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -24,6 +24,7 @@ import java.util.Map;
|
||||
import brave.SpanCustomizer;
|
||||
import brave.http.HttpClientRequest;
|
||||
import brave.http.HttpRequest;
|
||||
import brave.propagation.TraceContext;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
@@ -38,6 +39,8 @@ import static org.mockito.Mockito.when;
|
||||
@Deprecated
|
||||
public class SleuthHttpClientParserTests {
|
||||
|
||||
private TraceContext context = TraceContext.newBuilder().traceId(1).spanId(2).build();
|
||||
|
||||
private TraceKeys traceKeys = new TraceKeys();
|
||||
|
||||
private TestSpan span = new TestSpan();
|
||||
@@ -50,7 +53,7 @@ public class SleuthHttpClientParserTests {
|
||||
when(request.method()).thenReturn("GET");
|
||||
when(request.url()).thenReturn("https://foo/" + bigName());
|
||||
|
||||
parser.parse(request, null, span);
|
||||
parser.parse(request, context, span);
|
||||
|
||||
then(this.span.name).hasSize(50);
|
||||
}
|
||||
@@ -70,7 +73,7 @@ public class SleuthHttpClientParserTests {
|
||||
when(request.url()).thenReturn("http://localhost/?foo=bar");
|
||||
when(request.header("host")).thenReturn("localhost");
|
||||
|
||||
parser.parse(request, null, span);
|
||||
parser.parse(request, context, span);
|
||||
|
||||
then(this.span.tags).containsEntry("http.url", "http://localhost/?foo=bar")
|
||||
.containsEntry("http.host", "localhost").containsEntry("http.path", "/")
|
||||
@@ -84,7 +87,7 @@ public class SleuthHttpClientParserTests {
|
||||
HttpRequest request = mock(HttpRequest.class);
|
||||
when(request.header("x-foo")).thenReturn("bar");
|
||||
|
||||
parser.parse(request, null, span);
|
||||
parser.parse(request, context, span);
|
||||
|
||||
then(this.span.tags).containsEntry("http.x-foo", "bar");
|
||||
}
|
||||
@@ -131,7 +134,7 @@ public class SleuthHttpClientParserTests {
|
||||
@Override
|
||||
public void header(String name, String value) {
|
||||
}
|
||||
}, null, this.span);
|
||||
}, context, this.span);
|
||||
|
||||
then(this.span.tags).containsEntry("http.user-agent", "Test")
|
||||
.containsEntry("http.accept", "'text/plain','text/xml'")
|
||||
|
||||
@@ -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))));
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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).build();
|
||||
@@ -77,6 +76,12 @@ public class FeignRetriesTests {
|
||||
.willReturn(this.httpTracing);
|
||||
}
|
||||
|
||||
@After
|
||||
public void close() {
|
||||
this.tracing.close();
|
||||
this.currentTraceContext.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRetriedWhenExceededNumberOfRetries() {
|
||||
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;
|
||||
@@ -54,9 +52,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).build();
|
||||
@@ -67,13 +65,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;
|
||||
@@ -49,11 +49,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();
|
||||
@@ -70,6 +70,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");
|
||||
|
||||
@@ -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 com.netflix.zuul.context.RequestContext;
|
||||
import com.netflix.zuul.monitoring.TracerFactory;
|
||||
import org.junit.After;
|
||||
@@ -55,11 +54,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).build();
|
||||
@@ -71,7 +70,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,8 +31,8 @@
|
||||
<name>spring-cloud-sleuth-dependencies</name>
|
||||
<description>Spring Cloud Sleuth Dependencies</description>
|
||||
<properties>
|
||||
<brave.version>5.10.2</brave.version>
|
||||
<brave.opentracing.version>0.35.1</brave.opentracing.version>
|
||||
<brave.version>5.11.0</brave.version>
|
||||
<brave.opentracing.version>0.36.0</brave.opentracing.version>
|
||||
<grpc.spring.boot.version>3.4.1</grpc.spring.boot.version>
|
||||
</properties>
|
||||
<dependencyManagement>
|
||||
|
||||
@@ -21,7 +21,6 @@ import java.nio.charset.StandardCharsets;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import brave.Tracing;
|
||||
import brave.sampler.Sampler;
|
||||
import feign.Client;
|
||||
import feign.Request;
|
||||
@@ -68,9 +67,6 @@ public class ManuallyCreatedLoadBalancerFeignClientTests {
|
||||
@Autowired
|
||||
ArrayListSpanReporter reporter;
|
||||
|
||||
@Autowired
|
||||
Tracing tracer;
|
||||
|
||||
@Before
|
||||
public void open() {
|
||||
this.reporter.clear();
|
||||
|
||||
@@ -20,7 +20,6 @@ import java.nio.charset.StandardCharsets;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import brave.Tracing;
|
||||
import brave.sampler.Sampler;
|
||||
import feign.Client;
|
||||
import feign.Request;
|
||||
@@ -72,9 +71,6 @@ public class Issue502Tests {
|
||||
@Autowired
|
||||
ArrayListSpanReporter reporter;
|
||||
|
||||
@Autowired
|
||||
Tracing tracer;
|
||||
|
||||
@Before
|
||||
public void open() {
|
||||
this.reporter.clear();
|
||||
|
||||
@@ -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;
|
||||
@@ -154,11 +153,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();
|
||||
}
|
||||
|
||||
|
||||
@@ -22,9 +22,9 @@ import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import brave.Tracing;
|
||||
import brave.http.HttpRequest;
|
||||
import brave.http.HttpRequestParser;
|
||||
import brave.propagation.CurrentTraceContext;
|
||||
import brave.sampler.Sampler;
|
||||
import brave.sampler.SamplerFunction;
|
||||
import org.assertj.core.api.BDDAssertions;
|
||||
@@ -64,6 +64,9 @@ import static org.assertj.core.api.BDDAssertions.then;
|
||||
properties = "spring.sleuth.http.legacy.enabled=true")
|
||||
public class TraceFilterWebIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
CurrentTraceContext currentTraceContext;
|
||||
|
||||
@Autowired
|
||||
BlockingQueueSpanReporter reporter;
|
||||
|
||||
@@ -84,7 +87,7 @@ public class TraceFilterWebIntegrationTests {
|
||||
new RestTemplate().getForObject("http://localhost:" + port() + "/good",
|
||||
String.class);
|
||||
|
||||
then(Tracing.current().tracer().currentSpan()).isNull();
|
||||
then(this.currentTraceContext.get()).isNull();
|
||||
then(this.reporter.takeSpan().tags()).containsKey("http.url");
|
||||
}
|
||||
|
||||
@@ -98,7 +101,7 @@ public class TraceFilterWebIntegrationTests {
|
||||
catch (Exception e) {
|
||||
}
|
||||
|
||||
then(Tracing.current().tracer().currentSpan()).isNull();
|
||||
then(this.currentTraceContext.get()).isNull();
|
||||
Span fromFirstTraceFilterFlow = this.reporter.takeSpan();
|
||||
then(fromFirstTraceFilterFlow.tags()).containsEntry("http.method", "GET")
|
||||
.containsEntry("mvc.controller.class", "ExceptionThrowingController")
|
||||
@@ -124,7 +127,7 @@ public class TraceFilterWebIntegrationTests {
|
||||
catch (HttpClientErrorException e) {
|
||||
}
|
||||
|
||||
then(Tracing.current().tracer().currentSpan()).isNull();
|
||||
then(this.currentTraceContext.get()).isNull();
|
||||
Span span = this.reporter.takeSpan();
|
||||
then(span.kind().ordinal()).isEqualTo(Span.Kind.SERVER.ordinal());
|
||||
then(span.tags()).containsEntry("http.status_code", "400");
|
||||
|
||||
@@ -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.awaitility.Awaitility;
|
||||
@@ -76,6 +77,9 @@ public class RestTemplateTraceAspectIntegrationTests {
|
||||
@Autowired
|
||||
AspectTestingController controller;
|
||||
|
||||
@Autowired
|
||||
CurrentTraceContext currentTraceContext;
|
||||
|
||||
@Autowired
|
||||
Tracing tracer;
|
||||
|
||||
@@ -142,7 +146,7 @@ public class RestTemplateTraceAspectIntegrationTests {
|
||||
throws Exception {
|
||||
whenARequestIsSentToASyncEndpointThatShouldBeFilteredOut();
|
||||
|
||||
then(Tracing.current().tracer().currentSpan()).isNull();
|
||||
then(this.currentTraceContext.get()).isNull();
|
||||
then(this.reporter.getSpans()).isEmpty();
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
@@ -56,6 +57,9 @@ public class Issue585Tests {
|
||||
|
||||
TestRestTemplate testRestTemplate = new TestRestTemplate();
|
||||
|
||||
@Autowired
|
||||
CurrentTraceContext currentTraceContext;
|
||||
|
||||
@Autowired
|
||||
ArrayListSpanReporter reporter;
|
||||
|
||||
@@ -68,7 +72,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");
|
||||
|
||||
@@ -21,7 +21,7 @@ import java.util.function.Function;
|
||||
|
||||
import brave.propagation.CurrentTraceContext;
|
||||
import brave.propagation.CurrentTraceContext.Scope;
|
||||
import brave.propagation.StrictScopeDecorator;
|
||||
import brave.propagation.StrictCurrentTraceContext;
|
||||
import brave.propagation.TraceContext;
|
||||
import org.assertj.core.presentation.StandardRepresentation;
|
||||
import org.junit.After;
|
||||
@@ -59,8 +59,7 @@ public class ScopePassingSpanSubscriberTests {
|
||||
Objects::toString);
|
||||
}
|
||||
|
||||
final CurrentTraceContext currentTraceContext = CurrentTraceContext.Default
|
||||
.newBuilder().addScopeDecorator(StrictScopeDecorator.create()).build();
|
||||
StrictCurrentTraceContext currentTraceContext = StrictCurrentTraceContext.create();
|
||||
|
||||
TraceContext context = TraceContext.newBuilder().traceId(1).spanId(1).sampled(true)
|
||||
.build();
|
||||
@@ -128,6 +127,7 @@ public class ScopePassingSpanSubscriberTests {
|
||||
@After
|
||||
public void close() {
|
||||
springContext.close();
|
||||
currentTraceContext.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -19,6 +19,7 @@ package org.springframework.cloud.sleuth.instrument.web.client;
|
||||
import java.net.URI;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
import brave.http.HttpTracing;
|
||||
import brave.propagation.CurrentTraceContext;
|
||||
@@ -33,7 +34,7 @@ import org.reactivestreams.Subscription;
|
||||
import reactor.core.publisher.BaseSubscriber;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.netty.http.client.HttpClient;
|
||||
import zipkin2.Callback;
|
||||
import zipkin2.Span;
|
||||
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
|
||||
@@ -99,8 +100,8 @@ abstract class ITSpringConfiguredReactorClient
|
||||
}
|
||||
|
||||
@Override
|
||||
final protected void getAsync(AnnotationConfigApplicationContext context, String path,
|
||||
Callback<Integer> callback) {
|
||||
final protected void get(AnnotationConfigApplicationContext context, String path,
|
||||
BiConsumer<Integer, Throwable> callback) {
|
||||
TestHttpCallbackSubscriber.subscribe(getMono(context, path), callback);
|
||||
}
|
||||
|
||||
@@ -160,7 +161,7 @@ abstract class ITSpringConfiguredReactorClient
|
||||
|
||||
assertThat(server.getRequestCount()).isOne();
|
||||
|
||||
takeClientSpanWithError("CANCELLED");
|
||||
reporter.takeRemoteSpanWithError(Span.Kind.CLIENT, "CANCELLED");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.springframework.cloud.sleuth.instrument.web.client;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
import org.reactivestreams.Subscription;
|
||||
import reactor.core.CoreSubscriber;
|
||||
@@ -36,15 +37,15 @@ import zipkin2.Callback;
|
||||
*/
|
||||
final class TestHttpCallbackSubscriber implements CoreSubscriber<Integer> {
|
||||
|
||||
static void subscribe(Mono<Integer> mono, Callback<Integer> callback) {
|
||||
static void subscribe(Mono<Integer> mono, BiConsumer<Integer, Throwable> callback) {
|
||||
mono.subscribe(new TestHttpCallbackSubscriber(callback));
|
||||
}
|
||||
|
||||
final Callback<Integer> callback;
|
||||
final BiConsumer<Integer, Throwable> callback;
|
||||
|
||||
final AtomicReference<Subscription> ref = new AtomicReference<>();
|
||||
|
||||
private TestHttpCallbackSubscriber(Callback<Integer> callback) {
|
||||
private TestHttpCallbackSubscriber(BiConsumer<Integer, Throwable> callback) {
|
||||
this.callback = callback;
|
||||
}
|
||||
|
||||
@@ -56,31 +57,31 @@ final class TestHttpCallbackSubscriber implements CoreSubscriber<Integer> {
|
||||
else {
|
||||
// We don't intentionally call subscribe() multiple times in our tests. If we
|
||||
// reach here, possibly instrumentation is redundantly subscribing.
|
||||
callback.onError(new AssertionError("onSubscribe() called twice!"));
|
||||
callback.accept(null, new AssertionError("onSubscribe() called twice!"));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(Integer t) {
|
||||
if (ref.getAndSet(null) != null) {
|
||||
callback.onSuccess(t);
|
||||
callback.accept(t, null);
|
||||
}
|
||||
else {
|
||||
// This is a Mono, which doesn't signal onNext() twice. If we reach here,
|
||||
// possibly instrumentation is signaling twice.
|
||||
callback.onError(new AssertionError("onNext() called twice!"));
|
||||
callback.accept(null, new AssertionError("onNext() called twice!"));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable t) {
|
||||
if (ref.getAndSet(null) != null) {
|
||||
callback.onError(t);
|
||||
callback.accept(null, t);
|
||||
}
|
||||
else {
|
||||
// We don't expect onError() to signal twice. If we reach here, possibly
|
||||
// instrumentation is signaling twice or onSuccess() threw an exception.
|
||||
callback.onError(new AssertionError("onError() called twice: " + t, t));
|
||||
callback.accept(null, new AssertionError("onError() called twice: " + t, t));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,7 +91,8 @@ final class TestHttpCallbackSubscriber implements CoreSubscriber<Integer> {
|
||||
// Tests make a non-empty Mono subscription, which should not signal
|
||||
// onComplete() before onNext(). If we reach here, possibly instrumentation
|
||||
// is not signaling onNext() when it should.
|
||||
callback.onError(new AssertionError("onComplete() called before onNext!"));
|
||||
callback.accept(null,
|
||||
new AssertionError("onComplete() called before onNext!"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user