Merge branch '2.2.x'
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.3.0.BUILD-SNAPSHOT</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
@@ -250,7 +250,7 @@
|
||||
<spring-cloud-stream.version>Horsham.BUILD-SNAPSHOT</spring-cloud-stream.version>
|
||||
<spring-cloud-netflix.version>3.0.0.BUILD-SNAPSHOT</spring-cloud-netflix.version>
|
||||
<spring-cloud-openfeign.version>3.0.0.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>
|
||||
<disable.nohttp.checks>false</disable.nohttp.checks>
|
||||
<okhttp.version>3.14.6</okhttp.version>
|
||||
|
||||
@@ -187,7 +187,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>
|
||||
|
||||
@@ -16,23 +16,21 @@
|
||||
|
||||
package org.springframework.cloud.sleuth.instrument.reactor;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
import brave.Tracing;
|
||||
import brave.propagation.CurrentTraceContext;
|
||||
import brave.propagation.TraceContext;
|
||||
import java.util.function.Function;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.reactivestreams.Publisher;
|
||||
import org.springframework.cloud.sleuth.internal.LazyBean;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import reactor.core.CoreSubscriber;
|
||||
import reactor.core.Fuseable;
|
||||
import reactor.core.Scannable;
|
||||
import reactor.core.publisher.Operators;
|
||||
import reactor.util.context.Context;
|
||||
|
||||
import org.springframework.cloud.sleuth.internal.LazyBean;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
|
||||
/**
|
||||
* Reactive Span pointcuts factories.
|
||||
*
|
||||
@@ -82,12 +80,15 @@ public abstract class ReactorSleuth {
|
||||
}
|
||||
|
||||
if (!springContext.isActive()) {
|
||||
if (log.isTraceEnabled()) {
|
||||
log.trace("Spring Context [" + springContext
|
||||
boolean assertOn = false;
|
||||
assert assertOn = true; // gives a message in unit tests even if trace disabled!
|
||||
if (log.isTraceEnabled() || assertOn) {
|
||||
String message = "Spring Context [" + springContext
|
||||
+ "] is not yet refreshed. This is unexpected. Reactor Context is ["
|
||||
+ sub.currentContext() + "] and name is [" + name(sub) + "]");
|
||||
+ sub.currentContext() + "] and name is [" + name(sub) + "]";
|
||||
log.trace(message);
|
||||
assert false : message; // should never happen, but don't break.
|
||||
}
|
||||
assert false; // should never happen, but don't break.
|
||||
return sub;
|
||||
}
|
||||
|
||||
@@ -101,12 +102,15 @@ public abstract class ReactorSleuth {
|
||||
// Try to get the current trace context bean, lenient when there are problems
|
||||
CurrentTraceContext currentTraceContext = lazyCurrentTraceContext.get();
|
||||
if (currentTraceContext == null) {
|
||||
if (log.isTraceEnabled()) {
|
||||
log.trace("Spring Context [" + springContext
|
||||
boolean assertOn = false;
|
||||
assert assertOn = true; // gives a message in unit tests even if trace disabled!
|
||||
if (log.isTraceEnabled() || assertOn) {
|
||||
String message = "Spring Context [" + springContext
|
||||
+ "] did not return a CurrentTraceContext. Reactor Context is ["
|
||||
+ sub.currentContext() + "] and name is [" + name(sub) + "]");
|
||||
+ sub.currentContext() + "] and name is [" + name(sub) + "]";
|
||||
log.trace(message);
|
||||
assert false : message; // should never happen, but don't break.
|
||||
}
|
||||
assert false; // should never happen, but don't break.
|
||||
return sub;
|
||||
}
|
||||
|
||||
|
||||
@@ -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.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.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();
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
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.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
@@ -43,9 +43,9 @@ import org.springframework.util.ErrorHandler;
|
||||
@ExtendWith(MockitoExtension.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(lenient = true)
|
||||
@@ -62,6 +62,13 @@ public class LazyTraceThreadPoolTaskSchedulerTests {
|
||||
this.delegate);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
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.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.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("");
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
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.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.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);
|
||||
|
||||
@AfterEach
|
||||
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.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
@@ -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();
|
||||
|
||||
@AfterEach
|
||||
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.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
@@ -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();
|
||||
|
||||
@AfterEach
|
||||
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.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
@@ -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 {
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void tearDown() throws Exception {
|
||||
public void tearDown() {
|
||||
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.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
@@ -48,9 +48,9 @@ import static org.mockito.Mockito.never;
|
||||
@ExtendWith(MockitoExtension.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(lenient = true)
|
||||
@@ -67,6 +67,12 @@ public class TraceableScheduledExecutorServiceTest {
|
||||
beanFactory();
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
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.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.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();
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void close() {
|
||||
this.tracing.close();
|
||||
this.currentTraceContext.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_pass_tracing_information_when_using_circuit_breaker() {
|
||||
// given
|
||||
|
||||
@@ -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.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.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 {
|
||||
}
|
||||
};
|
||||
|
||||
@AfterEach
|
||||
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();
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
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.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.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();
|
||||
|
||||
@BeforeEach
|
||||
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 {
|
||||
|
||||
@AfterEach
|
||||
public void tearDown() throws Exception {
|
||||
scheduler.shutdown(true);
|
||||
this.scheduler.shutdown(true);
|
||||
this.tracing.close();
|
||||
this.currentTraceContext.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -26,8 +26,7 @@ import brave.Tracer;
|
||||
import brave.Tracing;
|
||||
import brave.http.HttpClientParser;
|
||||
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.junit.jupiter.api.AfterEach;
|
||||
@@ -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();
|
||||
@@ -84,7 +83,8 @@ public class TraceRestTemplateInterceptorTests {
|
||||
|
||||
@AfterEach
|
||||
public void clean() {
|
||||
Tracing.current().close();
|
||||
this.tracing.close();
|
||||
this.currentTraceContext.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -139,9 +139,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))));
|
||||
|
||||
@@ -16,13 +16,19 @@
|
||||
|
||||
package org.springframework.cloud.sleuth.instrument.web.client;
|
||||
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
import brave.propagation.TraceContext;
|
||||
import io.netty.bootstrap.Bootstrap;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import reactor.core.publisher.Hooks;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.core.publisher.SynchronousSink;
|
||||
import reactor.core.scheduler.Schedulers;
|
||||
import reactor.netty.Connection;
|
||||
|
||||
import org.springframework.cloud.sleuth.instrument.web.client.HttpClientBeanPostProcessor.PendingSpan;
|
||||
@@ -42,15 +48,27 @@ public class HttpClientBeanPostProcessorTest {
|
||||
TraceContext traceContext = TraceContext.newBuilder().traceId(1).spanId(2)
|
||||
.sampled(true).build();
|
||||
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
Hooks.resetOnEachOperator();
|
||||
Hooks.resetOnLastOperator();
|
||||
Schedulers.resetOnScheduleHooks();
|
||||
}
|
||||
|
||||
@Test
|
||||
void mapConnect_should_setup_reactor_context_currentTraceContext() {
|
||||
TracingMapConnect tracingMapConnect = new TracingMapConnect(() -> traceContext);
|
||||
|
||||
Mono<Connection> original = Mono.just(connection).handle((t, ctx) -> {
|
||||
assertThat(ctx.currentContext().get(TraceContext.class))
|
||||
.isSameAs(traceContext);
|
||||
assertThat(ctx.currentContext().get(PendingSpan.class)).isNotNull();
|
||||
});
|
||||
Mono<Connection> original = Mono.just(connection)
|
||||
.handle(new BiConsumer<Connection, SynchronousSink<Connection>>() {
|
||||
@Override
|
||||
public void accept(Connection t, SynchronousSink<Connection> ctx) {
|
||||
assertThat(ctx.currentContext().get(TraceContext.class))
|
||||
.isSameAs(traceContext);
|
||||
assertThat(ctx.currentContext().get(PendingSpan.class))
|
||||
.isNotNull();
|
||||
}
|
||||
});
|
||||
|
||||
// Wrap and run the assertions
|
||||
tracingMapConnect.apply(original, bootstrap).log().subscribe();
|
||||
@@ -60,10 +78,16 @@ public class HttpClientBeanPostProcessorTest {
|
||||
void mapConnect_should_setup_reactor_context_no_currentTraceContext() {
|
||||
TracingMapConnect tracingMapConnect = new TracingMapConnect(() -> null);
|
||||
|
||||
Mono<Connection> original = Mono.just(connection).handle((t, ctx) -> {
|
||||
assertThat(ctx.currentContext().getOrEmpty(TraceContext.class)).isEmpty();
|
||||
assertThat(ctx.currentContext().get(PendingSpan.class)).isNotNull();
|
||||
});
|
||||
Mono<Connection> original = Mono.just(connection)
|
||||
.handle(new BiConsumer<Connection, SynchronousSink<Connection>>() {
|
||||
@Override
|
||||
public void accept(Connection t, SynchronousSink<Connection> ctx) {
|
||||
assertThat(ctx.currentContext().getOrEmpty(TraceContext.class))
|
||||
.isEmpty();
|
||||
assertThat(ctx.currentContext().get(PendingSpan.class))
|
||||
.isNotNull();
|
||||
}
|
||||
});
|
||||
|
||||
// Wrap and run the assertions
|
||||
tracingMapConnect.apply(original, bootstrap).log().subscribe();
|
||||
|
||||
@@ -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.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.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();
|
||||
|
||||
@AfterEach
|
||||
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.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.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();
|
||||
|
||||
@AfterEach
|
||||
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;
|
||||
@@ -60,11 +59,11 @@ public class TraceRestTemplateInterceptorIntegrationTests {
|
||||
mockWebServer.close();
|
||||
}
|
||||
|
||||
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();
|
||||
@@ -80,7 +79,8 @@ public class TraceRestTemplateInterceptorIntegrationTests {
|
||||
|
||||
@AfterEach
|
||||
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;
|
||||
@@ -69,11 +68,11 @@ public class FeignRetriesTests {
|
||||
@Mock(lenient = true)
|
||||
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();
|
||||
@@ -85,6 +84,12 @@ public class FeignRetriesTests {
|
||||
.willReturn(this.httpTracing);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
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.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
@@ -51,9 +49,9 @@ public class TraceFeignAspectTests {
|
||||
@Mock
|
||||
ProceedingJoinPoint pjp;
|
||||
|
||||
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();
|
||||
@@ -64,13 +62,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;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
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.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
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");
|
||||
|
||||
@@ -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.http.HttpRequest;
|
||||
import brave.sampler.Sampler;
|
||||
import brave.sampler.SamplerFunction;
|
||||
@@ -66,9 +65,6 @@ public class ManuallyCreatedLoadBalancerFeignClientTests {
|
||||
@Autowired
|
||||
MyBlockingClient myClient;
|
||||
|
||||
@Autowired
|
||||
Tracing tracer;
|
||||
|
||||
@BeforeEach
|
||||
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.http.HttpRequest;
|
||||
import brave.sampler.Sampler;
|
||||
import brave.sampler.SamplerFunction;
|
||||
@@ -71,9 +70,6 @@ public class Issue502Tests {
|
||||
@Autowired
|
||||
ArrayListSpanReporter reporter;
|
||||
|
||||
@Autowired
|
||||
Tracing tracer;
|
||||
|
||||
@BeforeEach
|
||||
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.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -73,12 +72,6 @@ public class ITTracingChannelInterceptorTests implements MessageHandler {
|
||||
@Autowired
|
||||
Tracer tracer;
|
||||
|
||||
@Autowired
|
||||
List<zipkin2.Span> spans;
|
||||
|
||||
@Autowired
|
||||
MessagingTemplate messagingTemplate;
|
||||
|
||||
Message<?> message;
|
||||
|
||||
Span currentSpan;
|
||||
@@ -151,11 +144,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.apache.commons.logging.Log;
|
||||
@@ -65,6 +65,9 @@ import static org.assertj.core.api.BDDAssertions.then;
|
||||
@ExtendWith(OutputCaptureExtension.class)
|
||||
public class TraceFilterWebIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
CurrentTraceContext currentTraceContext;
|
||||
|
||||
@Autowired
|
||||
BlockingQueueSpanReporter reporter;
|
||||
|
||||
@@ -85,7 +88,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");
|
||||
}
|
||||
|
||||
@@ -99,7 +102,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")
|
||||
@@ -130,7 +133,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;
|
||||
@@ -73,6 +74,9 @@ public class RestTemplateTraceAspectIntegrationTests {
|
||||
@Autowired
|
||||
AspectTestingController controller;
|
||||
|
||||
@Autowired
|
||||
CurrentTraceContext currentTraceContext;
|
||||
|
||||
@Autowired
|
||||
Tracing tracer;
|
||||
|
||||
@@ -139,7 +143,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.jupiter.api.Test;
|
||||
@@ -53,6 +54,9 @@ public class Issue585Tests {
|
||||
|
||||
TestRestTemplate testRestTemplate = new TestRestTemplate();
|
||||
|
||||
@Autowired
|
||||
CurrentTraceContext currentTraceContext;
|
||||
|
||||
@Autowired
|
||||
ArrayListSpanReporter reporter;
|
||||
|
||||
@@ -65,7 +69,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");
|
||||
|
||||
@@ -18,8 +18,8 @@ package org.springframework.cloud.sleuth.instrument.reactor;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import brave.propagation.CurrentTraceContext;
|
||||
import brave.propagation.CurrentTraceContext.Scope;
|
||||
import brave.propagation.StrictCurrentTraceContext;
|
||||
import brave.propagation.TraceContext;
|
||||
import org.assertj.core.presentation.StandardRepresentation;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
@@ -46,7 +46,7 @@ public class ScopePassingSpanSubscriberTests {
|
||||
Objects::toString);
|
||||
}
|
||||
|
||||
final CurrentTraceContext currentTraceContext = CurrentTraceContext.Default.create();
|
||||
StrictCurrentTraceContext currentTraceContext = StrictCurrentTraceContext.create();
|
||||
|
||||
TraceContext context = TraceContext.newBuilder().traceId(1).spanId(1).sampled(true)
|
||||
.build();
|
||||
@@ -59,6 +59,7 @@ public class ScopePassingSpanSubscriberTests {
|
||||
@AfterEach
|
||||
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;
|
||||
@@ -35,7 +36,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.cloud.sleuth.instrument.reactor.TraceReactorAutoConfigurationAccessorConfiguration;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
@@ -108,8 +109,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);
|
||||
}
|
||||
|
||||
@@ -169,7 +170,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.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.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();
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
|
||||
Reference in New Issue
Block a user