This commit is contained in:
Marcin Grzejszczak
2018-12-14 08:41:35 +00:00
parent 4afb5836e8
commit 0326f279ce
49 changed files with 326 additions and 326 deletions

View File

@@ -132,7 +132,7 @@ class ReactorSleuthMethodInvocationProcessor
Tracer tracer = this.processor.tracer();
if (this.span == null) {
span = tracer.nextSpan();
this.processor.newSpanParser().parse(invocation, newSpan, span);
this.processor.newSpanParser().parse(this.invocation, this.newSpan, span);
span.start();
}
else {
@@ -178,7 +178,7 @@ class ReactorSleuthMethodInvocationProcessor
Tracer tracer = this.processor.tracer();
if (this.span == null) {
span = tracer.nextSpan();
this.processor.newSpanParser().parse(invocation, newSpan, span);
this.processor.newSpanParser().parse(this.invocation, this.newSpan, span);
span.start();
}
else {
@@ -251,7 +251,7 @@ class ReactorSleuthMethodInvocationProcessor
@Override
public Context currentContext() {
return context;
return this.context;
}
@Override

View File

@@ -130,8 +130,8 @@ public class TraceAutoConfiguration {
return B3Propagation.FACTORY;
}
ExtraFieldPropagation.FactoryBuilder factoryBuilder;
if (extraFieldPropagationFactoryBuilder != null) {
factoryBuilder = extraFieldPropagationFactoryBuilder;
if (this.extraFieldPropagationFactoryBuilder != null) {
factoryBuilder = this.extraFieldPropagationFactoryBuilder;
}
else {
factoryBuilder = ExtraFieldPropagation

View File

@@ -64,7 +64,7 @@ final class SpanSubscriptionProvider<T> implements Supplier<SpanSubscription<T>>
}
SpanSubscription<T> newCoreSubscriber(Tracing tracing) {
Span root = context.hasKey(Span.class) ? context.get(Span.class)
Span root = this.context.hasKey(Span.class) ? this.context.get(Span.class)
: tracing.tracer().currentSpan();
return new ScopePassingSpanSubscriber<>(this.subscriber, this.context, tracing,
root);

View File

@@ -292,7 +292,7 @@ public final class TraceWebFilter implements WebFilter, Ordered {
Span span;
if (c.hasKey(Span.class)) {
Span parent = c.get(Span.class);
span = tracer
span = this.tracer
.nextSpan(TraceContextOrSamplingFlags.create(parent.context()))
.start();
if (log.isDebugEnabled()) {

View File

@@ -256,12 +256,12 @@ final class TraceExchangeFilterFunction implements ExchangeFilterFunction {
@Override
public void onNext(ClientResponse response) {
done = true;
this.done = true;
try {
// decorate response body
this.actual.onNext(ClientResponse.from(response)
.body(response.bodyToFlux(DataBuffer.class)
.transform(scopePassingTransformer))
.transform(this.scopePassingTransformer))
.build());
}
finally {
@@ -285,7 +285,7 @@ final class TraceExchangeFilterFunction implements ExchangeFilterFunction {
this.actual.onComplete();
}
finally {
if (!done) {
if (!this.done) {
terminateSpan(null, null);
}
}
@@ -304,22 +304,22 @@ final class TraceExchangeFilterFunction implements ExchangeFilterFunction {
void terminateSpanOnCancel() {
if (log.isDebugEnabled()) {
log.debug("Subscription was cancelled. Will close the span [" + span
log.debug("Subscription was cancelled. Will close the span [" + this.span
+ "]");
}
span.tag("error", CANCELLED_SUBSCRIPTION_ERROR);
handleReceive(span, ws, null, null);
this.span.tag("error", CANCELLED_SUBSCRIPTION_ERROR);
handleReceive(this.span, this.ws, null, null);
}
void terminateSpan(@Nullable ClientResponse clientResponse,
@Nullable Throwable throwable) {
if (clientResponse == null || clientResponse.statusCode() == null) {
if (log.isDebugEnabled()) {
log.debug("No response was returned. Will close the span [" + span
log.debug("No response was returned. Will close the span [" + this.span
+ "]");
}
handleReceive(span, ws, clientResponse, throwable);
handleReceive(this.span, this.ws, clientResponse, throwable);
return;
}
boolean error = clientResponse.statusCode().is4xxClientError()
@@ -328,14 +328,14 @@ final class TraceExchangeFilterFunction implements ExchangeFilterFunction {
if (log.isDebugEnabled()) {
log.debug(
"Non positive status code was returned from the call. Will close the span ["
+ span + "]");
+ this.span + "]");
}
throwable = new RestClientException("Status code of the response is ["
+ clientResponse.statusCode().value()
+ "] and the reason is ["
+ clientResponse.statusCode().getReasonPhrase() + "]");
}
handleReceive(span, ws, clientResponse, throwable);
handleReceive(this.span, this.ws, clientResponse, throwable);
}
}

View File

@@ -65,7 +65,7 @@ public class SleuthSpanCreatorAspectFluxTests {
@Before
public void setup() {
this.reporter.clear();
testBean.reset();
this.testBean.reset();
}
@Test
@@ -397,13 +397,13 @@ public class SleuthSpanCreatorAspectFluxTests {
Iterator<String> iterator = flux.toIterable().iterator();
then(this.reporter.getSpans()).isEmpty();
testBean.proceed();
this.testBean.proceed();
String result1 = iterator.next();
then(result1).isEqualTo(TEST_STRING1);
then(this.reporter.getSpans()).isEmpty();
testBean.proceed();
this.testBean.proceed();
String result2 = iterator.next();
then(result2).isEqualTo(TEST_STRING2);
@@ -486,8 +486,8 @@ public class SleuthSpanCreatorAspectFluxTests {
private Flux<String> testFlux = Flux
.defer(() -> Flux.just(TEST_STRING1, TEST_STRING2))
.delayUntil(s -> Mono.fromFuture(proceed.get()))
.doOnNext(s -> proceed.set(new CompletableFuture<>()));
.delayUntil(s -> Mono.fromFuture(this.proceed.get()))
.doOnNext(s -> this.proceed.set(new CompletableFuture<>()));
public TestBean(Tracer tracer) {
this.tracer = tracer;
@@ -495,80 +495,80 @@ public class SleuthSpanCreatorAspectFluxTests {
@Override
public void reset() {
proceed.set(new CompletableFuture<>());
this.proceed.set(new CompletableFuture<>());
}
public void proceed() {
proceed.get().complete(null);
this.proceed.get().complete(null);
}
@Override
public Flux<String> testMethod() {
return testFlux;
return this.testFlux;
}
@NewSpan
@Override
public Flux<String> testMethod2() {
return testFlux;
return this.testFlux;
}
// tag::name_on_implementation[]
@NewSpan(name = "customNameOnTestMethod3")
@Override
public Flux<String> testMethod3() {
return testFlux;
return this.testFlux;
}
// end::name_on_implementation[]
@Override
public Flux<String> testMethod4() {
return testFlux;
return this.testFlux;
}
@Override
public Flux<String> testMethod5(String test) {
return testFlux;
return this.testFlux;
}
@NewSpan(name = "customNameOnTestMethod6")
@Override
public Flux<String> testMethod6(@SpanTag("testTag6") String test) {
return testFlux;
return this.testFlux;
}
@Override
public Flux<String> testMethod7() {
return testFlux;
return this.testFlux;
}
@Override
public Flux<String> testMethod8(String param) {
return testFlux;
return this.testFlux;
}
@NewSpan(name = "customNameOnTestMethod9")
@Override
public Flux<String> testMethod9(String param) {
return testFlux;
return this.testFlux;
}
@Override
public Flux<String> testMethod10(
@SpanTag(value = "customTestTag10") String param) {
return testFlux;
return this.testFlux;
}
@Override
public Flux<String> testMethod10_v2(
@SpanTag(key = "customTestTag10") String param) {
return testFlux;
return this.testFlux;
}
@ContinueSpan(log = "customTest")
@Override
public Flux<String> testMethod11(@SpanTag("customTestTag11") String param) {
return testFlux;
return this.testFlux;
}
@Override
@@ -590,13 +590,13 @@ public class SleuthSpanCreatorAspectFluxTests {
@Override
public Flux<Long> newSpanInTraceContext() {
return Flux.defer(() -> Flux.just(id(tracer)));
return Flux.defer(() -> Flux.just(id(this.tracer)));
}
@Override
public Flux<Long> newSpanInSubscriberContext() {
return Mono.subscriberContext()
.flatMapMany(context -> Flux.just(id(context, tracer)));
.flatMapMany(context -> Flux.just(id(context, this.tracer)));
}
}

View File

@@ -619,12 +619,12 @@ public class SleuthSpanCreatorAspectMonoTests {
@Override
public Mono<Long> newSpanInTraceContext() {
return Mono.defer(() -> Mono.just(id(tracer)));
return Mono.defer(() -> Mono.just(id(this.tracer)));
}
@Override
public Mono<Long> newSpanInSubscriberContext() {
return Mono.subscriberContext().flatMap(context -> Mono.just(id(tracer)));
return Mono.subscriberContext().flatMap(context -> Mono.just(id(this.tracer)));
}
}
@@ -642,17 +642,17 @@ public class SleuthSpanCreatorAspectMonoTests {
@NewSpan(name = "outerSpanInTraceContext")
public Mono<Pair<Pair<Long, Long>, Long>> outerNewSpanInTraceContext() {
return Mono.defer(() -> Mono.just(id(tracer))
.zipWith(testBeanInterface.newSpanInTraceContext()).map(pair -> Pair
.of(Pair.of(pair.getT1(), id(tracer)), pair.getT2())));
return Mono.defer(() -> Mono.just(id(this.tracer))
.zipWith(this.testBeanInterface.newSpanInTraceContext()).map(pair -> Pair
.of(Pair.of(pair.getT1(), id(this.tracer)), pair.getT2())));
}
@NewSpan(name = "outerSpanInSubscriberContext")
public Mono<Pair<Pair<Long, Long>, Long>> outerNewSpanInSubscriberContext() {
return Mono.subscriberContext()
.flatMap(context -> Mono.just(id(tracer))
.zipWith(testBeanInterface.newSpanInSubscriberContext())
.map(pair -> Pair.of(Pair.of(pair.getT1(), id(tracer)),
.flatMap(context -> Mono.just(id(this.tracer))
.zipWith(this.testBeanInterface.newSpanInSubscriberContext())
.map(pair -> Pair.of(Pair.of(pair.getT1(), id(this.tracer)),
pair.getT2())));
}

View File

@@ -58,7 +58,7 @@ public class SpanTagAnnotationHandlerTests {
.getMethod("getAnnotationForTagValueResolver", String.class);
Annotation annotation = method.getParameterAnnotations()[0][0];
if (annotation instanceof SpanTag) {
String resolvedValue = handler.resolveTagValue((SpanTag) annotation, "test");
String resolvedValue = this.handler.resolveTagValue((SpanTag) annotation, "test");
assertThat(resolvedValue).isEqualTo("Value from myCustomTagValueResolver");
}
else {
@@ -73,7 +73,7 @@ public class SpanTagAnnotationHandlerTests {
.getMethod("getAnnotationForTagValueExpression", String.class);
Annotation annotation = method.getParameterAnnotations()[0][0];
if (annotation instanceof SpanTag) {
String resolvedValue = handler.resolveTagValue((SpanTag) annotation, "test");
String resolvedValue = this.handler.resolveTagValue((SpanTag) annotation, "test");
assertThat(resolvedValue).isEqualTo("hello characters");
}
@@ -89,7 +89,7 @@ public class SpanTagAnnotationHandlerTests {
.getMethod("getAnnotationForArgumentToString", Long.class);
Annotation annotation = method.getParameterAnnotations()[0][0];
if (annotation instanceof SpanTag) {
String resolvedValue = handler.resolveTagValue((SpanTag) annotation, 15);
String resolvedValue = this.handler.resolveTagValue((SpanTag) annotation, 15);
assertThat(resolvedValue).isEqualTo("15");
}
else {

View File

@@ -59,7 +59,7 @@ public class SpringCloudSleuthDocTests {
.addScopeDecorator(StrictScopeDecorator.create()).build())
.sampler(Sampler.ALWAYS_SAMPLE).spanReporter(this.reporter).build();
Tracer tracer = tracing.tracer();
Tracer tracer = this.tracing.tracer();
@Before
public void setup() {
@@ -97,7 +97,7 @@ public class SpringCloudSleuthDocTests {
SpanNamer spanNamer = new DefaultSpanNamer();
// tag::span_name_annotated_runnable_execution[]
Runnable runnable = new TraceRunnable(tracing, spanNamer,
Runnable runnable = new TraceRunnable(this.tracing, spanNamer,
new TaxCountingRunnable());
Future<?> future = executorService.submit(runnable);
// ... some additional logic ...
@@ -116,7 +116,7 @@ public class SpringCloudSleuthDocTests {
SpanNamer spanNamer = new DefaultSpanNamer();
// tag::span_name_to_string_runnable_execution[]
Runnable runnable = new TraceRunnable(tracing, spanNamer, new Runnable() {
Runnable runnable = new TraceRunnable(this.tracing, spanNamer, new Runnable() {
@Override
public void run() {
// perform logic
@@ -265,11 +265,11 @@ public class SpringCloudSleuthDocTests {
}
};
// Manual `TraceRunnable` creation with explicit "calculateTax" Span name
Runnable traceRunnable = new TraceRunnable(tracing, spanNamer, runnable,
Runnable traceRunnable = new TraceRunnable(this.tracing, spanNamer, runnable,
"calculateTax");
// Wrapping `Runnable` with `Tracing`. That way the current span will be available
// in the thread of `Runnable`
Runnable traceRunnableFromTracer = tracing.currentTraceContext().wrap(runnable);
Runnable traceRunnableFromTracer = this.tracing.currentTraceContext().wrap(runnable);
// end::trace_runnable[]
then(traceRunnable).isExactlyInstanceOf(TraceRunnable.class);
@@ -291,11 +291,11 @@ public class SpringCloudSleuthDocTests {
}
};
// Manual `TraceCallable` creation with explicit "calculateTax" Span name
Callable<String> traceCallable = new TraceCallable<>(tracing, spanNamer, callable,
Callable<String> traceCallable = new TraceCallable<>(this.tracing, spanNamer, callable,
"calculateTax");
// Wrapping `Callable` with `Tracing`. That way the current span will be available
// in the thread of `Callable`
Callable<String> traceCallableFromTracer = tracing.currentTraceContext()
Callable<String> traceCallableFromTracer = this.tracing.currentTraceContext()
.wrap(callable);
// end::trace_callable[]
}

View File

@@ -71,10 +71,10 @@ public class ExecutorBeanPostProcessorTests {
@Before
public void setup() {
this.sleuthAsyncProperties = new SleuthAsyncProperties();
Mockito.when(beanFactory.getBean(SleuthAsyncProperties.class))
Mockito.when(this.beanFactory.getBean(SleuthAsyncProperties.class))
.thenReturn(this.sleuthAsyncProperties);
Mockito.when(beanFactory.getBean(Tracing.class)).thenReturn(this.tracing);
Mockito.when(beanFactory.getBean(SpanNamer.class))
Mockito.when(this.beanFactory.getBean(Tracing.class)).thenReturn(this.tracing);
Mockito.when(this.beanFactory.getBean(SpanNamer.class))
.thenReturn(new DefaultSpanNamer());
}

View File

@@ -116,7 +116,7 @@ public class TraceCallableTests {
return new Callable<Span>() {
@Override
public Span call() throws Exception {
return tracer.currentSpan();
return TraceCallableTests.this.tracer.currentSpan();
}
@Override

View File

@@ -142,7 +142,7 @@ public class TraceRunnableTests {
return new Runnable() {
@Override
public void run() {
span.set(tracer.currentSpan());
span.set(TraceRunnableTests.this.tracer.currentSpan());
}
@Override

View File

@@ -290,7 +290,7 @@ class AsyncTask {
}
public AtomicReference<Span> getSpan() {
return span;
return this.span;
}
}

View File

@@ -103,9 +103,9 @@ class Controller {
public void asyncTest(@RequestParam(required = false) boolean isSleep)
throws InterruptedException {
log.info("(/trace-async-rest-template) I got a request!");
final long traceId = tracer.tracer().currentSpan().context().traceId();
ListenableFuture<ResponseEntity<HogeBean>> res = traceAsyncRestTemplate
.getForEntity("http://localhost:" + port + "/bean", HogeBean.class);
final long traceId = this.tracer.tracer().currentSpan().context().traceId();
ListenableFuture<ResponseEntity<HogeBean>> res = this.traceAsyncRestTemplate
.getForEntity("http://localhost:" + this.port + "/bean", HogeBean.class);
if (isSleep) {
Thread.sleep(1000);
}

View File

@@ -114,7 +114,7 @@ public class HystrixAnnotationsIntegrationTests {
@HystrixCommand
public void invokeLogicWrappedInHystrixCommand() {
this.spanCaughtFromHystrixThread = new AtomicReference<>(
tracing.tracer().currentSpan());
this.tracing.tracer().currentSpan());
}
public Long getTraceId() {

View File

@@ -82,61 +82,61 @@ public class ITTracingChannelInterceptor implements MessageHandler {
@Override
public void handleMessage(Message<?> msg) {
message = msg;
currentSpan = tracer.currentSpan();
if (message.getHeaders().containsKey("THROW_EXCEPTION")) {
this.message = msg;
this.currentSpan = this.tracer.currentSpan();
if (this.message.getHeaders().containsKey("THROW_EXCEPTION")) {
throw new RuntimeException("A terrible exception has occurred");
}
}
@Before
public void init() {
directChannel.subscribe(this);
executorChannel.subscribe(this);
this.directChannel.subscribe(this);
this.executorChannel.subscribe(this);
}
@After
public void close() {
directChannel.unsubscribe(this);
executorChannel.unsubscribe(this);
this.directChannel.unsubscribe(this);
this.executorChannel.unsubscribe(this);
}
// formerly known as TraceChannelInterceptorTest.executableSpanCreation
@Test
public void propagatesNoopSpan() {
directChannel.send(
this.directChannel.send(
MessageBuilder.withPayload("hi").setHeader("X-B3-Sampled", "0").build());
assertThat(message.getHeaders()).containsEntry("X-B3-Sampled", "0");
assertThat(this.message.getHeaders()).containsEntry("X-B3-Sampled", "0");
assertThat(currentSpan.isNoop()).isTrue();
assertThat(this.currentSpan.isNoop()).isTrue();
}
@Test
public void messageHeadersStillMutableForStomp() {
directChannel.send(MessageBuilder.withPayload("hi")
this.directChannel.send(MessageBuilder.withPayload("hi")
.setHeader("stompCommand", "DISCONNECT").build());
assertThat(
MessageHeaderAccessor.getAccessor(message, MessageHeaderAccessor.class))
MessageHeaderAccessor.getAccessor(this.message, MessageHeaderAccessor.class))
.isNotNull();
message = null;
directChannel.send(MessageBuilder.withPayload("hi")
this.message = null;
this.directChannel.send(MessageBuilder.withPayload("hi")
.setHeader("simpMessageType", "sth").build());
assertThat(
MessageHeaderAccessor.getAccessor(message, MessageHeaderAccessor.class))
MessageHeaderAccessor.getAccessor(this.message, MessageHeaderAccessor.class))
.isNotNull();
}
@Test
public void messageHeadersImmutableForNonStomp() {
directChannel
this.directChannel
.send(MessageBuilder.withPayload("hi").setHeader("foo", "bar").build());
assertThat(
MessageHeaderAccessor.getAccessor(message, MessageHeaderAccessor.class))
MessageHeaderAccessor.getAccessor(this.message, MessageHeaderAccessor.class))
.isNull();
}

View File

@@ -77,12 +77,12 @@ public class JmsTracingConfigurationTest {
@Test
public void tracesConnectionFactory() {
contextRunner.run(JmsTracingConfigurationTest::checkConnection);
this.contextRunner.run(JmsTracingConfigurationTest::checkConnection);
}
@Test
public void tracesXAConnectionFactories() {
contextRunner.withUserConfiguration(XAConfiguration.class).run(ctx -> {
this.contextRunner.withUserConfiguration(XAConfiguration.class).run(ctx -> {
clearSpans(ctx);
checkConnection(ctx);
checkXAConnection(ctx);
@@ -101,7 +101,7 @@ public class JmsTracingConfigurationTest {
@Test
public void tracesListener_jmsMessageListener() {
contextRunner.withUserConfiguration(SimpleJmsListenerConfiguration.class)
this.contextRunner.withUserConfiguration(SimpleJmsListenerConfiguration.class)
.run(ctx -> {
clearSpans(ctx);
ctx.getBean(JmsTemplate.class).convertAndSend("myQueue", "foo");
@@ -129,7 +129,7 @@ public class JmsTracingConfigurationTest {
SimpleJmsListenerEndpoint endpoint = new SimpleJmsListenerEndpoint();
endpoint.setId("myCustomEndpointId");
endpoint.setDestination("myQueue");
endpoint.setMessageListener(simpleMessageListener(current));
endpoint.setMessageListener(simpleMessageListener(this.current));
registrar.registerEndpoint(endpoint);
}
@@ -146,7 +146,7 @@ public class JmsTracingConfigurationTest {
@Test
public void tracesListener_annotationMessageListener() {
contextRunner.withUserConfiguration(AnnotationJmsListenerConfiguration.class)
this.contextRunner.withUserConfiguration(AnnotationJmsListenerConfiguration.class)
.run(ctx -> {
clearSpans(ctx);
ctx.getBean(JmsTemplate.class).convertAndSend("myQueue", "foo");
@@ -171,7 +171,7 @@ public class JmsTracingConfigurationTest {
@JmsListener(destination = "myQueue")
public void onMessage() {
assertThat(current.get()).extracting(TraceContext::parentIdAsLong)
assertThat(this.current.get()).extracting(TraceContext::parentIdAsLong)
.isNotEqualTo(0L);
}
@@ -179,7 +179,7 @@ public class JmsTracingConfigurationTest {
@Test
public void tracesListener_jcaMessageListener() {
contextRunner.withUserConfiguration(JcaJmsListenerConfiguration.class)
this.contextRunner.withUserConfiguration(JcaJmsListenerConfiguration.class)
.run(ctx -> {
clearSpans(ctx);
ctx.getBean(JmsTemplate.class).convertAndSend("myQueue", "foo");
@@ -296,7 +296,7 @@ class JmsTestTracingConfiguration {
@Bean
Callable<Span> takeSpan() {
return () -> {
Span result = spans.poll(3, TimeUnit.SECONDS);
Span result = this.spans.poll(3, TimeUnit.SECONDS);
assertThat(result).withFailMessage("Span was not reported").isNotNull();
assertThat(result.annotations()).extracting(Annotation::value)
.doesNotContain(CONTEXT_LEAK);
@@ -319,7 +319,7 @@ class JmsTestTracingConfiguration {
contextLeak = true;
}
}
spans.add(s);
this.spans.add(s);
// throw so that we can see the path to the code that leaked the context
if (contextLeak) {
throw new AssertionError(

View File

@@ -37,7 +37,7 @@ public class MessageHeaderPropagationTest
@Override
protected MessageHeaderAccessor carrier() {
return carrier;
return this.carrier;
}
@Override

View File

@@ -36,7 +36,7 @@ public class MessageHeaderPropagation_NativeTest
@Override
protected MessageHeaderAccessor carrier() {
return carrier;
return this.carrier;
}
@Override

View File

@@ -53,7 +53,7 @@ public class TracingChannelInterceptorTest {
ChannelInterceptor interceptor = TracingChannelInterceptor.create(Tracing.newBuilder()
.currentTraceContext(ThreadLocalCurrentTraceContext.newBuilder()
.addScopeDecorator(StrictScopeDecorator.create()).build())
.spanReporter(spans::add).build());
.spanReporter(this.spans::add).build());
QueueChannel channel = new QueueChannel();
@@ -64,50 +64,50 @@ public class TracingChannelInterceptorTest {
MessageHandler handler = new MessageHandler() {
@Override
public void handleMessage(Message<?> msg) throws MessagingException {
message = msg;
TracingChannelInterceptorTest.this.message = msg;
}
};
@Test
public void pollingReceive_emptyQueue() {
channel.addInterceptor(consumerSideOnly(interceptor));
this.channel.addInterceptor(consumerSideOnly(this.interceptor));
assertThat(channel.receive(0)).isNull();
assertThat(spans).hasSize(0);
assertThat(this.channel.receive(0)).isNull();
assertThat(this.spans).hasSize(0);
}
@Test
public void injectsProducerSpan() {
channel.addInterceptor(producerSideOnly(interceptor));
this.channel.addInterceptor(producerSideOnly(this.interceptor));
channel.send(MessageBuilder.withPayload("foo").build());
this.channel.send(MessageBuilder.withPayload("foo").build());
assertThat(channel.receive().getHeaders()).containsKeys("X-B3-TraceId",
assertThat(this.channel.receive().getHeaders()).containsKeys("X-B3-TraceId",
"X-B3-SpanId", "X-B3-Sampled", "nativeHeaders");
assertThat(spans).hasSize(1).flatExtracting(Span::kind)
assertThat(this.spans).hasSize(1).flatExtracting(Span::kind)
.containsExactly(Span.Kind.PRODUCER);
}
@Test
public void injectsProducerAndConsumerSpan() {
directChannel.addInterceptor(interceptor);
directChannel.subscribe(this.handler);
directChannel.send(MessageBuilder.withPayload("foo").build());
this.directChannel.addInterceptor(this.interceptor);
this.directChannel.subscribe(this.handler);
this.directChannel.send(MessageBuilder.withPayload("foo").build());
assertThat(message).isNotNull();
assertThat(message.getHeaders()).containsKeys("X-B3-TraceId", "X-B3-SpanId",
assertThat(this.message).isNotNull();
assertThat(this.message.getHeaders()).containsKeys("X-B3-TraceId", "X-B3-SpanId",
"X-B3-Sampled", "nativeHeaders");
assertThat(spans).flatExtracting(Span::kind).contains(Span.Kind.CONSUMER,
assertThat(this.spans).flatExtracting(Span::kind).contains(Span.Kind.CONSUMER,
Span.Kind.PRODUCER);
}
@Test
public void injectsProducerSpan_nativeHeaders() {
channel.addInterceptor(producerSideOnly(interceptor));
this.channel.addInterceptor(producerSideOnly(this.interceptor));
channel.send(MessageBuilder.withPayload("foo").build());
this.channel.send(MessageBuilder.withPayload("foo").build());
assertThat((Map) channel.receive().getHeaders().get(NATIVE_HEADERS))
assertThat((Map) this.channel.receive().getHeaders().get(NATIVE_HEADERS))
.containsOnlyKeys("X-B3-TraceId", "X-B3-SpanId", "X-B3-Sampled",
"spanTraceId", "spanId", "spanSampled");
}
@@ -119,20 +119,20 @@ public class TracingChannelInterceptorTest {
*/
@Test
public void producerConsidersOldSpanIds() {
channel.addInterceptor(producerSideOnly(interceptor));
this.channel.addInterceptor(producerSideOnly(this.interceptor));
channel.send(MessageBuilder.withPayload("foo")
this.channel.send(MessageBuilder.withPayload("foo")
.setHeader("X-B3-TraceId", "000000000000000a")
.setHeader("X-B3-ParentSpanId", "000000000000000a")
.setHeader("X-B3-SpanId", "000000000000000b").build());
assertThat(channel.receive().getHeaders()).containsEntry("X-B3-ParentSpanId",
assertThat(this.channel.receive().getHeaders()).containsEntry("X-B3-ParentSpanId",
"000000000000000b");
}
@Test
public void producerConsidersOldSpanIds_nativeHeaders() {
channel.addInterceptor(producerSideOnly(interceptor));
this.channel.addInterceptor(producerSideOnly(this.interceptor));
NativeMessageHeaderAccessor accessor = new NativeMessageHeaderAccessor() {
};
@@ -141,10 +141,10 @@ public class TracingChannelInterceptorTest {
accessor.setNativeHeader("X-B3-ParentSpanId", "000000000000000a");
accessor.setNativeHeader("X-B3-SpanId", "000000000000000b");
channel.send(MessageBuilder.withPayload("foo")
this.channel.send(MessageBuilder.withPayload("foo")
.copyHeaders(accessor.toMessageHeaders()).build());
assertThat((Map) channel.receive().getHeaders().get(NATIVE_HEADERS))
assertThat((Map) this.channel.receive().getHeaders().get(NATIVE_HEADERS))
.containsEntry("X-B3-ParentSpanId",
Collections.singletonList("000000000000000b"));
}
@@ -155,23 +155,23 @@ public class TracingChannelInterceptorTest {
*/
@Test
public void pollingReceive_injectsConsumerSpan() {
channel.addInterceptor(consumerSideOnly(interceptor));
this.channel.addInterceptor(consumerSideOnly(this.interceptor));
channel.send(MessageBuilder.withPayload("foo").build());
this.channel.send(MessageBuilder.withPayload("foo").build());
assertThat(channel.receive().getHeaders()).containsKeys("X-B3-TraceId",
assertThat(this.channel.receive().getHeaders()).containsKeys("X-B3-TraceId",
"X-B3-SpanId", "X-B3-Sampled", "nativeHeaders");
assertThat(spans).hasSize(1).flatExtracting(Span::kind)
assertThat(this.spans).hasSize(1).flatExtracting(Span::kind)
.containsExactly(Span.Kind.CONSUMER);
}
@Test
public void pollingReceive_injectsConsumerSpan_nativeHeaders() {
channel.addInterceptor(consumerSideOnly(interceptor));
this.channel.addInterceptor(consumerSideOnly(this.interceptor));
channel.send(MessageBuilder.withPayload("foo").build());
this.channel.send(MessageBuilder.withPayload("foo").build());
assertThat((Map) channel.receive().getHeaders().get(NATIVE_HEADERS))
assertThat((Map) this.channel.receive().getHeaders().get(NATIVE_HEADERS))
.containsOnlyKeys("X-B3-TraceId", "X-B3-SpanId", "X-B3-Sampled",
"spanTraceId", "spanId", "spanSampled");
}
@@ -179,7 +179,7 @@ public class TracingChannelInterceptorTest {
@Test
public void subscriber_startsAndStopsConsumerAndProcessingSpan() {
ExecutorSubscribableChannel channel = new ExecutorSubscribableChannel();
channel.addInterceptor(executorSideOnly(interceptor));
channel.addInterceptor(executorSideOnly(this.interceptor));
List<Message<?>> messages = new ArrayList<>();
channel.subscribe(messages::add);
@@ -187,7 +187,7 @@ public class TracingChannelInterceptorTest {
assertThat(messages.get(0).getHeaders()).doesNotContainKeys("X-B3-TraceId",
"X-B3-SpanId", "X-B3-Sampled", "nativeHeaders");
assertThat(spans).flatExtracting(Span::kind).containsExactly(Span.Kind.CONSUMER,
assertThat(this.spans).flatExtracting(Span::kind).containsExactly(Span.Kind.CONSUMER,
null);
}
@@ -199,7 +199,7 @@ public class TracingChannelInterceptorTest {
@Test
public void subscriber_removesTraceIdsFromMessage() {
ExecutorSubscribableChannel channel = new ExecutorSubscribableChannel();
channel.addInterceptor(interceptor);
channel.addInterceptor(this.interceptor);
List<Message<?>> messages = new ArrayList<>();
channel.subscribe(messages::add);
@@ -212,7 +212,7 @@ public class TracingChannelInterceptorTest {
@Test
public void subscriber_removesTraceIdsFromMessage_nativeHeaders() {
ExecutorSubscribableChannel channel = new ExecutorSubscribableChannel();
channel.addInterceptor(interceptor);
channel.addInterceptor(this.interceptor);
List<Message<?>> messages = new ArrayList<>();
channel.subscribe(messages::add);
@@ -224,31 +224,31 @@ public class TracingChannelInterceptorTest {
@Test
public void integrated_sendAndPoll() {
channel.addInterceptor(interceptor);
this.channel.addInterceptor(this.interceptor);
channel.send(MessageBuilder.withPayload("foo").build());
channel.receive();
this.channel.send(MessageBuilder.withPayload("foo").build());
this.channel.receive();
assertThat(spans).flatExtracting(Span::kind)
assertThat(this.spans).flatExtracting(Span::kind)
.containsExactlyInAnyOrder(Span.Kind.CONSUMER, Span.Kind.PRODUCER);
}
@Test
public void integrated_sendAndSubscriber() {
ExecutorSubscribableChannel channel = new ExecutorSubscribableChannel();
channel.addInterceptor(interceptor);
channel.addInterceptor(this.interceptor);
List<Message<?>> messages = new ArrayList<>();
channel.subscribe(messages::add);
channel.send(MessageBuilder.withPayload("foo").build());
assertThat(spans).flatExtracting(Span::kind).containsExactly(Span.Kind.CONSUMER,
assertThat(this.spans).flatExtracting(Span::kind).containsExactly(Span.Kind.CONSUMER,
null, Span.Kind.PRODUCER);
}
@Test
public void errorMessageHeadersRetained() {
this.channel.addInterceptor(interceptor);
this.channel.addInterceptor(this.interceptor);
QueueChannel deadReplyChannel = new QueueChannel();
QueueChannel errorsReplyChannel = new QueueChannel();
Map<String, Object> errorChannelHeaders = new HashMap<>();

View File

@@ -50,10 +50,10 @@ public class HelloWorldRestController {
requestMessage[1] = "Hellow World Message 2";
requestMessage[2] = "Hellow World Message 3";
PollableChannel outputChannel = (PollableChannel) applicationContext
PollableChannel outputChannel = (PollableChannel) this.applicationContext
.getBean("messagingOutputChannel");
MessagingGateway messagingGateway = (MessagingGateway) applicationContext
MessagingGateway messagingGateway = (MessagingGateway) this.applicationContext
.getBean("messagingGateway");
messagingGateway.processMessage(requestMessage);

View File

@@ -68,7 +68,7 @@ public class BraveTracerTest {
@Test
public void startWithOpenTracingAndFinishWithBrave() {
io.opentracing.Span openTracingSpan = opentracing.buildSpan("encode")
io.opentracing.Span openTracingSpan = this.opentracing.buildSpan("encode")
.withTag("lc", "codec").withStartTimestamp(1L).start();
Span braveSpan = ((BraveSpan) openTracingSpan).unwrap();
@@ -86,7 +86,7 @@ public class BraveTracerTest {
map.put("X-B3-SpanId", "0000000000000002");
map.put("X-B3-Sampled", "1");
BraveSpanContext openTracingContext = (BraveSpanContext) opentracing
BraveSpanContext openTracingContext = (BraveSpanContext) this.opentracing
.extract(Format.Builtin.HTTP_HEADERS, new TextMapExtractAdapter(map));
assertThat(openTracingContext.unwrap()).isEqualTo(
@@ -101,7 +101,7 @@ public class BraveTracerTest {
map.put("X-B3-Sampled", "1");
map.put("baggage-country-code", "FO");
BraveSpanContext openTracingContext = opentracing
BraveSpanContext openTracingContext = this.opentracing
.extract(Format.Builtin.HTTP_HEADERS, new TextMapExtractAdapter(map));
assertThat(openTracingContext.baggageItems())
@@ -115,7 +115,7 @@ public class BraveTracerTest {
map.put("X-B3-SpanId", "0000000000000002");
map.put("X-B3-Sampled", "1");
BraveSpanContext openTracingContext = (BraveSpanContext) opentracing
BraveSpanContext openTracingContext = (BraveSpanContext) this.opentracing
.extract(Format.Builtin.TEXT_MAP, new TextMapExtractAdapter(map));
assertThat(openTracingContext.unwrap()).isEqualTo(
@@ -130,7 +130,7 @@ public class BraveTracerTest {
map.put("x-b3-SaMpLeD", "1");
map.put("other", "1");
BraveSpanContext openTracingContext = (BraveSpanContext) opentracing
BraveSpanContext openTracingContext = (BraveSpanContext) this.opentracing
.extract(Format.Builtin.HTTP_HEADERS, new TextMapExtractAdapter(map));
assertThat(openTracingContext.unwrap()).isEqualTo(
@@ -139,18 +139,18 @@ public class BraveTracerTest {
@Test
public void injectTraceContext_baggage() throws Exception {
BraveSpan span = opentracing.buildSpan("foo").start();
BraveSpan span = this.opentracing.buildSpan("foo").start();
span.setBaggageItem("country-code", "FO");
Map<String, String> map = new LinkedHashMap<>();
TextMapInjectAdapter carrier = new TextMapInjectAdapter(map);
opentracing.inject(span.context(), Format.Builtin.HTTP_HEADERS, carrier);
this.opentracing.inject(span.context(), Format.Builtin.HTTP_HEADERS, carrier);
assertThat(map).containsEntry("baggage-country-code", "FO");
}
void checkSpanReportedToZipkin() {
assertThat(spans.getSpans()).first().satisfies(s -> {
assertThat(this.spans.getSpans()).first().satisfies(s -> {
assertThat(s.name()).isEqualTo("encode");
assertThat(s.timestamp()).isEqualTo(1L);
assertThat(s.annotations())
@@ -173,17 +173,17 @@ public class BraveTracerTest {
Long parentIdOfSpanB;
Long parentIdOfSpanC;
try (Scope scopeA = opentracing.buildSpan("spanA").startActive(false)) {
try (Scope scopeA = this.opentracing.buildSpan("spanA").startActive(false)) {
idOfSpanA = getTraceContext(scopeA).spanId();
try (Scope scopeB = opentracing.buildSpan("spanB").startActive(false)) {
try (Scope scopeB = this.opentracing.buildSpan("spanB").startActive(false)) {
idOfSpanB = getTraceContext(scopeB).spanId();
parentIdOfSpanB = getTraceContext(scopeB).parentId();
shouldBeIdOfSpanB = getTraceContext(opentracing.scopeManager().active())
shouldBeIdOfSpanB = getTraceContext(this.opentracing.scopeManager().active())
.spanId();
}
shouldBeIdOfSpanA = getTraceContext(opentracing.scopeManager().active())
shouldBeIdOfSpanA = getTraceContext(this.opentracing.scopeManager().active())
.spanId();
try (Scope scopeC = opentracing.buildSpan("spanC").startActive(false)) {
try (Scope scopeC = this.opentracing.buildSpan("spanC").startActive(false)) {
parentIdOfSpanC = getTraceContext(scopeC).parentId();
}
}
@@ -208,25 +208,25 @@ public class BraveTracerTest {
Long parentIdOfSpanB;
Long parentIdOfSpanC;
Span spanA = brave.tracer().newTrace().name("spanA").start();
Span spanA = this.brave.tracer().newTrace().name("spanA").start();
Long idOfSpanA = spanA.context().spanId();
try (SpanInScope scopeA = brave.tracer().withSpanInScope(spanA)) {
try (SpanInScope scopeA = this.brave.tracer().withSpanInScope(spanA)) {
Span spanB = brave.tracer().newChild(spanA.context()).name("spanB").start();
Span spanB = this.brave.tracer().newChild(spanA.context()).name("spanB").start();
idOfSpanB = spanB.context().spanId();
parentIdOfSpanB = spanB.context().parentId();
try (SpanInScope scopeB = brave.tracer().withSpanInScope(spanB)) {
shouldBeIdOfSpanB = brave.currentTraceContext().get().spanId();
try (SpanInScope scopeB = this.brave.tracer().withSpanInScope(spanB)) {
shouldBeIdOfSpanB = this.brave.currentTraceContext().get().spanId();
}
finally {
spanB.finish();
}
shouldBeIdOfSpanA = brave.currentTraceContext().get().spanId();
shouldBeIdOfSpanA = this.brave.currentTraceContext().get().spanId();
Span spanC = brave.tracer().newChild(spanA.context()).name("spanC").start();
Span spanC = this.brave.tracer().newChild(spanA.context()).name("spanC").start();
parentIdOfSpanC = spanC.context().parentId();
try (SpanInScope scopeC = brave.tracer().withSpanInScope(spanC)) {
try (SpanInScope scopeC = this.brave.tracer().withSpanInScope(spanC)) {
// nothing to do here
}
finally {
@@ -247,8 +247,8 @@ public class BraveTracerTest {
@Test
public void implicitParentFromSpanManager_startActive() {
try (Scope scopeA = opentracing.buildSpan("spanA").startActive(true)) {
try (Scope scopeB = opentracing.buildSpan("spanA").startActive(true)) {
try (Scope scopeA = this.opentracing.buildSpan("spanA").startActive(true)) {
try (Scope scopeB = this.opentracing.buildSpan("spanA").startActive(true)) {
assertThat(getTraceContext(scopeB).parentId())
.isEqualTo(getTraceContext(scopeA).spanId());
}
@@ -257,8 +257,8 @@ public class BraveTracerTest {
@Test
public void implicitParentFromSpanManager_start() {
try (Scope scopeA = opentracing.buildSpan("spanA").startActive(true)) {
BraveSpan span = opentracing.buildSpan("spanB").start();
try (Scope scopeA = this.opentracing.buildSpan("spanA").startActive(true)) {
BraveSpan span = this.opentracing.buildSpan("spanB").start();
assertThat(span.unwrap().context().parentId())
.isEqualTo(getTraceContext(scopeA).spanId());
}
@@ -266,8 +266,8 @@ public class BraveTracerTest {
@Test
public void implicitParentFromSpanManager_startActive_ignoreActiveSpan() {
try (Scope scopeA = opentracing.buildSpan("spanA").startActive(true)) {
try (Scope scopeB = opentracing.buildSpan("spanA").ignoreActiveSpan()
try (Scope scopeA = this.opentracing.buildSpan("spanA").startActive(true)) {
try (Scope scopeB = this.opentracing.buildSpan("spanA").ignoreActiveSpan()
.startActive(true)) {
assertThat(getTraceContext(scopeB).parentId()).isNull(); // new trace
}
@@ -276,24 +276,24 @@ public class BraveTracerTest {
@Test
public void implicitParentFromSpanManager_start_ignoreActiveSpan() {
try (Scope scopeA = opentracing.buildSpan("spanA").startActive(true)) {
BraveSpan span = opentracing.buildSpan("spanB").ignoreActiveSpan().start();
try (Scope scopeA = this.opentracing.buildSpan("spanA").startActive(true)) {
BraveSpan span = this.opentracing.buildSpan("spanB").ignoreActiveSpan().start();
assertThat(span.unwrap().context().parentId()).isNull(); // new trace
}
}
@Test
public void ignoresErrorFalseTag_beforeStart() {
opentracing.buildSpan("encode").withTag("error", false).start().finish();
this.opentracing.buildSpan("encode").withTag("error", false).start().finish();
assertThat(spans.getSpans().get(0).tags()).isEmpty();
assertThat(this.spans.getSpans().get(0).tags()).isEmpty();
}
@Test
public void ignoresErrorFalseTag_afterStart() {
opentracing.buildSpan("encode").start().setTag("error", false).finish();
this.opentracing.buildSpan("encode").start().setTag("error", false).finish();
assertThat(spans.getSpans().get(0).tags()).isEmpty();
assertThat(this.spans.getSpans().get(0).tags()).isEmpty();
}
private static TraceContext getTraceContext(Scope scope) {

View File

@@ -58,7 +58,7 @@ public class ScopePassingSpanSubscriberTests {
try (Tracer.SpanInScope ws = this.tracing.tracer()
.withSpanInScope(span.start())) {
CoreSubscriber<?> subscriber = ReactorSleuth
.scopePassingSpanSubscription(tracing, new BaseSubscriber<Object>() {
.scopePassingSpanSubscription(this.tracing, new BaseSubscriber<Object>() {
});
then(subscriber.currentContext().get(Span.class)).isEqualTo(span);

View File

@@ -112,7 +112,7 @@ public class SpanSubscriberTests {
try (Tracer.SpanInScope ws = this.tracer.withSpanInScope(span)) {
Function<? super Publisher<Integer>, ? extends Publisher<Integer>> transformer = ReactorSleuth
.scopePassingSpanOperator(factory);
.scopePassingSpanOperator(this.factory);
Subscriber<Object> assertNoSpanSubscriber = new CoreSubscriber<Object>() {
@Override
@@ -236,11 +236,11 @@ public class SpanSubscriberTests {
Span parentSpan = this.tracer.nextSpan().name("foo").start();
log.info("Hello");
try (Tracer.SpanInScope ws = this.tracer.withSpanInScope(parentSpan)) {
final Long spanId = Mono.fromCallable(tracer::currentSpan)
final Long spanId = Mono.fromCallable(this.tracer::currentSpan)
.map(span -> span.context().spanId()).block();
then(spanId).isNotNull();
final Long secondSpanId = Mono.fromCallable(tracer::currentSpan)
final Long secondSpanId = Mono.fromCallable(this.tracer::currentSpan)
.map(span -> span.context().spanId()).block();
then(secondSpanId).isEqualTo(spanId); // different trace ids here
}
@@ -253,9 +253,9 @@ public class SpanSubscriberTests {
final AtomicReference<Long> spanInZipOperation = new AtomicReference<>();
try (Tracer.SpanInScope ws = this.tracer.withSpanInScope(initSpan)) {
Mono.fromCallable(tracer::currentSpan).map(span -> span.context().spanId())
Mono.fromCallable(this.tracer::currentSpan).map(span -> span.context().spanId())
.doOnNext(spanInOperation::set)
.zipWith(Mono.fromCallable(tracer::currentSpan)
.zipWith(Mono.fromCallable(this.tracer::currentSpan)
.map(span -> span.context().spanId())
.doOnNext(spanInZipOperation::set))
.block();
@@ -290,7 +290,7 @@ public class SpanSubscriberTests {
try (Tracer.SpanInScope ws = this.tracer.withSpanInScope(initSpan)) {
Mono.subscriberContext()
.map(context -> tracer.currentSpan().context().spanId())
.map(context -> this.tracer.currentSpan().context().spanId())
.doOnNext(spanInSubscriberContext::set).block();
}

View File

@@ -116,7 +116,7 @@ public class FlatMapTests {
thenSpanInFooHasSameTraceId(secondTraceId, config);
LOGGER.info("Span in Foo has same trace id");
// and
List<String> requestUri = Arrays.stream(capture.toString().split("\n"))
List<String> requestUri = Arrays.stream(this.capture.toString().split("\n"))
.filter(s -> s.contains("Received a request to uri"))
.map(s -> s.split(",")[1]).collect(Collectors.toList());
LOGGER.info(
@@ -185,7 +185,7 @@ public class FlatMapTests {
return ServerResponse.ok().body(response, Integer.class);
}).andRoute(GET("/foo"), request -> {
LOGGER.info("foo");
spanInFoo = tracer.currentSpan();
this.spanInFoo = tracer.currentSpan();
return ServerResponse.ok().body(Flux.just(1), Integer.class);
});
}

View File

@@ -45,7 +45,7 @@ class RequestSender {
public Mono<String> get(Integer someParameterNotUsedNow) {
LOGGER.info("getting for parameter {}", someParameterNotUsedNow);
this.span = this.tracer.currentSpan();
return webClient.method(HttpMethod.GET)
return this.webClient.method(HttpMethod.GET)
.uri("http://localhost:" + this.port + "/foo").retrieve()
.bodyToMono(String.class);
}

View File

@@ -79,7 +79,7 @@ public class SleuthRxJavaSchedulersHookTests {
RxJavaPlugins.getInstance()
.registerObservableExecutionHook(new MyRxJavaObservableExecutionHook());
new SleuthRxJavaSchedulersHook(this.tracer, threadsToIgnore);
new SleuthRxJavaSchedulersHook(this.tracer, this.threadsToIgnore);
then(RxJavaPlugins.getInstance().getErrorHandler())
.isExactlyInstanceOf(MyRxJavaErrorHandler.class);

View File

@@ -42,7 +42,7 @@ public class CompositeHttpSamplerTests {
@Before
public void init() {
this.sampler = new CompositeHttpSampler(left, right);
this.sampler = new CompositeHttpSampler(this.left, this.right);
}
@Test

View File

@@ -56,7 +56,7 @@ public class SleuthHttpClientParserTests {
@Override
public String url(Object request) {
return url.toString();
return this.url.toString();
}
@Override

View File

@@ -77,7 +77,7 @@ public class SpringDataInstrumentationTests {
@Before
public void setup() {
reporter.clear();
this.reporter.clear();
}
@Test
@@ -152,8 +152,8 @@ class SampleRecords {
public void create() throws Exception {
Stream.of("Josh", "Jungryeol", "Nosung", "Hyobeom", "Soeun", "Seunghue", "Peter",
"Jooyong")
.forEach(name -> reservationRepository.save(new Reservation(name)));
reservationRepository.findAll().forEach(System.out::println);
.forEach(name -> this.reservationRepository.save(new Reservation(name)));
this.reservationRepository.findAll().forEach(System.out::println);
}
}
@@ -173,16 +173,16 @@ class Reservation {
private String reservationName; // reservation_name
public Long getId() {
return id;
return this.id;
}
public String getReservationName() {
return reservationName;
return this.reservationName;
}
@Override
public String toString() {
return "Reservation{" + "id=" + id + ", reservationName='" + reservationName
return "Reservation{" + "id=" + this.id + ", reservationName='" + this.reservationName
+ '\'' + '}';
}

View File

@@ -128,7 +128,7 @@ public class TraceFilterTests {
@Test
public void startsNewTrace() throws Exception {
filter.doFilter(this.request, this.response, this.filterChain);
this.filter.doFilter(this.request, this.response, this.filterChain);
then(this.reporter.getSpans()).hasSize(1);
then(this.reporter.getSpans().get(0).tags())
@@ -143,7 +143,7 @@ public class TraceFilterTests {
public void shouldNotStoreHttpStatusCodeWhenResponseCodeHasNotYetBeenSet()
throws Exception {
this.response.setStatus(0);
filter.doFilter(this.request, this.response, this.filterChain);
this.filter.doFilter(this.request, this.response, this.filterChain);
then(Tracing.current().tracer().currentSpan()).isNull();
then(this.reporter.getSpans()).hasSize(1);
@@ -158,7 +158,7 @@ public class TraceFilterTests {
.header(PARENT_SPAN_ID_NAME, SpanUtil.idToHex(3L))
.buildRequest(new MockServletContext());
filter.doFilter(this.request, this.response, this.filterChain);
this.filter.doFilter(this.request, this.response, this.filterChain);
then(Tracing.current().tracer().currentSpan()).isNull();
then(this.reporter.getSpans()).hasSize(1);
@@ -177,7 +177,7 @@ public class TraceFilterTests {
.header(PARENT_SPAN_ID_NAME, SpanUtil.idToHex(3L))
.header(SAMPLED_ID_NAME, 0).buildRequest(new MockServletContext());
filter.doFilter(this.request, this.response, (req, resp) -> {
this.filter.doFilter(this.request, this.response, (req, resp) -> {
this.filterChain.doFilter(req, resp);
span.set(this.tracing.tracer().currentSpan());
});
@@ -190,7 +190,7 @@ public class TraceFilterTests {
public void continuesSpanInRequestAttr() throws Exception {
Span span = this.tracer.nextSpan().name("http:foo");
filter.doFilter(this.request, this.response, this.filterChain);
this.filter.doFilter(this.request, this.response, this.filterChain);
then(Tracing.current().tracer().currentSpan()).isNull();
}
@@ -200,7 +200,7 @@ public class TraceFilterTests {
Span span = this.tracer.nextSpan().name("http:foo");
this.response.setStatus(404);
filter.doFilter(this.request, this.response, this.filterChain);
this.filter.doFilter(this.request, this.response, this.filterChain);
then(Tracing.current().tracer().currentSpan()).isNull();
then(this.reporter.getSpans()).hasSize(1);
@@ -213,7 +213,7 @@ public class TraceFilterTests {
this.response.setStatus(404);
then(Tracing.current().tracer().currentSpan()).isNull();
filter.doFilter(this.request, this.response, this.filterChain);
this.filter.doFilter(this.request, this.response, this.filterChain);
}
@Test
@@ -222,7 +222,7 @@ public class TraceFilterTests {
.header(TRACE_ID_NAME, SpanUtil.idToHex(20L))
.buildRequest(new MockServletContext());
filter.doFilter(this.request, this.response, this.filterChain);
this.filter.doFilter(this.request, this.response, this.filterChain);
then(Tracing.current().tracer().currentSpan()).isNull();
verifyParentSpanHttpTags();
@@ -255,7 +255,7 @@ public class TraceFilterTests {
this.traceKeys.getHttp().getHeaders().add("x-foo");
this.request.addHeader("X-Foo", "bar");
filter.doFilter(this.request, this.response, this.filterChain);
this.filter.doFilter(this.request, this.response, this.filterChain);
then(Tracing.current().tracer().currentSpan()).isNull();
then(this.reporter.getSpans()).hasSize(1);
@@ -270,7 +270,7 @@ public class TraceFilterTests {
this.traceKeys.getHttp().getHeaders().add("x-foo");
this.request.addHeader("X-Foo", "bar");
this.request.addHeader("X-Foo", "spam");
filter.doFilter(this.request, this.response, this.filterChain);
this.filter.doFilter(this.request, this.response, this.filterChain);
then(Tracing.current().tracer().currentSpan()).isNull();
then(this.reporter.getSpans()).hasSize(1);
@@ -293,7 +293,7 @@ public class TraceFilterTests {
}
};
try {
filter.doFilter(this.request, this.response, this.filterChain);
this.filter.doFilter(this.request, this.response, this.filterChain);
}
catch (RuntimeException e) {
assertEquals("Planned", e.getMessage());
@@ -314,7 +314,7 @@ public class TraceFilterTests {
this.response.setStatus(404);
then(Tracing.current().tracer().currentSpan()).isNull();
filter.doFilter(this.request, this.response, this.filterChain);
this.filter.doFilter(this.request, this.response, this.filterChain);
}
@Test
@@ -324,7 +324,7 @@ public class TraceFilterTests {
.buildRequest(new MockServletContext());
this.response.setStatus(200);
filter.doFilter(this.request, this.response, this.filterChain);
this.filter.doFilter(this.request, this.response, this.filterChain);
then(Tracing.current().tracer().currentSpan()).isNull();
then(this.reporter.getSpans()).hasSize(1);
@@ -337,7 +337,7 @@ public class TraceFilterTests {
.buildRequest(new MockServletContext());
this.response.setStatus(302);
filter.doFilter(this.request, this.response, this.filterChain);
this.filter.doFilter(this.request, this.response, this.filterChain);
then(Tracing.current().tracer().currentSpan()).isNull();
then(this.reporter.getSpans()).hasSize(1);
@@ -349,7 +349,7 @@ public class TraceFilterTests {
.header(TRACE_ID_NAME, SpanUtil.idToHex(20L))
.buildRequest(new MockServletContext());
filter.doFilter(this.request, this.response, this.filterChain);
this.filter.doFilter(this.request, this.response, this.filterChain);
then(Tracing.current().tracer().currentSpan()).isNull();
then(this.reporter.getSpans()).isNotEmpty();
@@ -363,7 +363,7 @@ public class TraceFilterTests {
.header(TRACE_ID_NAME, SpanUtil.idToHex(20L))
.buildRequest(new MockServletContext());
filter.doFilter(this.request, this.response, this.filterChain);
this.filter.doFilter(this.request, this.response, this.filterChain);
then(Tracing.current().tracer().currentSpan()).isNull();
then(this.reporter.getSpans()).isNotEmpty();
@@ -388,7 +388,7 @@ public class TraceFilterTests {
this.request = builder().header(SPAN_FLAGS, 0)
.buildRequest(new MockServletContext());
filter.doFilter(this.request, this.response, this.filterChain);
this.filter.doFilter(this.request, this.response, this.filterChain);
then(Tracing.current().tracer().currentSpan()).isNull();
then(this.reporter.getSpans()).isNotEmpty();
@@ -429,7 +429,7 @@ public class TraceFilterTests {
.buildRequest(new MockServletContext());
this.response.setStatus(295);
filter.doFilter(this.request, this.response, this.filterChain);
this.filter.doFilter(this.request, this.response, this.filterChain);
then(Tracing.current().tracer().currentSpan()).isNull();
then(this.reporter.getSpans()).hasSize(1);

View File

@@ -172,12 +172,12 @@ public class TraceFilterWebIntegrationMultipleFiltersTests {
@Override
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
Span currentSpan = tracer.tracer().currentSpan();
Span currentSpan = this.tracer.tracer().currentSpan();
this.span.set(currentSpan);
}
public AtomicReference<Span> getSpan() {
return span;
return this.span;
}
}

View File

@@ -103,7 +103,7 @@ public class TraceFilterWebIntegrationTests {
"Request processing failed; nested exception is java.lang.RuntimeException: Throwing exception");
// issue#714
String hex = fromFirstTraceFilterFlow.traceId();
String[] split = capture.toString().split("\n");
String[] split = this.capture.toString().split("\n");
List<String> list = Arrays.stream(split)
.filter(s -> s.contains("Uncaught exception thrown"))
.filter(s -> s.contains(hex + "," + hex + ",true]"))

View File

@@ -132,7 +132,7 @@ public class TraceRestTemplateInterceptorTests {
span.finish();
}
List<zipkin2.Span> spans = reporter.getSpans();
List<zipkin2.Span> spans = this.reporter.getSpans();
then(spans).isNotEmpty();
then(spans.get(0).tags()).containsEntry("http.url", "/foo?a=b")
.containsEntry("http.path", "/foo").containsEntry("http.method", "GET");
@@ -157,7 +157,7 @@ public class TraceRestTemplateInterceptorTests {
span.finish();
}
then(reporter.getSpans()).isEmpty();
then(this.reporter.getSpans()).isEmpty();
}
// issue #198
@@ -195,7 +195,7 @@ public class TraceRestTemplateInterceptorTests {
span.finish();
}
List<zipkin2.Span> spans = reporter.getSpans();
List<zipkin2.Span> spans = this.reporter.getSpans();
then(spans).hasSize(2);
String spanName = spans.get(0).name();
then(spanName).isEqualTo("http:/cas~fs~%c3%a5%cb%86%e2%80%99");
@@ -218,7 +218,7 @@ public class TraceRestTemplateInterceptorTests {
span.finish();
}
List<zipkin2.Span> spans = reporter.getSpans();
List<zipkin2.Span> spans = this.reporter.getSpans();
then(spans).isNotEmpty();
String spanName = spans.get(0).name();
then(spanName).hasSize(50);

View File

@@ -292,7 +292,7 @@ public class TraceWebFluxTests {
@GetMapping("/ping")
Mono<Long> ping() {
log.info("ping");
return Mono.just(tracer.currentSpan().context().spanId());
return Mono.just(this.tracer.currentSpan().context().spanId());
}
@GetMapping("/pingFromContext")
@@ -301,25 +301,25 @@ public class TraceWebFluxTests {
return Mono.subscriberContext()
.doOnSuccess(context -> log.info("Ping from context"))
.flatMap(context -> Mono
.just(tracer.currentSpan().context().spanId()));
.just(this.tracer.currentSpan().context().spanId()));
}
@GetMapping("/continueSpan")
Mono<Long> continueSpan() {
log.info("continueSpan");
return testBean.continueSpanInTraceContext();
return this.testBean.continueSpanInTraceContext();
}
@GetMapping("/newSpan1")
Mono<Long> newSpan1() {
log.info("newSpan1");
return testBean.newSpanInTraceContext();
return this.testBean.newSpanInTraceContext();
}
@GetMapping("/newSpan2")
Mono<Long> newSpan2() {
log.info("newSpan2");
return testBean.newSpanInSubscriberContext();
return this.testBean.newSpanInSubscriberContext();
}
}
@@ -367,7 +367,7 @@ class SleuthSpanCreatorAspectWebFlux {
public void shouldReturnSpanFromWebFluxTraceContext() {
setup();
Mono<Object> mono = webClient.get().uri("/test/ping").exchange()
Mono<Object> mono = this.webClient.get().uri("/test/ping").exchange()
.returnResult(Object.class).getResponseBody().single();
Object object = mono.block();
@@ -392,7 +392,7 @@ class SleuthSpanCreatorAspectWebFlux {
public void shouldReturnSpanFromWebFluxSubscriptionContext() {
setup();
Mono<Object> mono = webClient.get().uri("/test/pingFromContext").exchange()
Mono<Object> mono = this.webClient.get().uri("/test/pingFromContext").exchange()
.returnResult(Object.class).getResponseBody().single();
Object object = mono.block();
@@ -411,7 +411,7 @@ class SleuthSpanCreatorAspectWebFlux {
public void shouldContinueSpanInWebFlux() {
setup();
Mono<Object> mono = webClient.get().uri("/test/continueSpan").exchange()
Mono<Object> mono = this.webClient.get().uri("/test/continueSpan").exchange()
.returnResult(Object.class).getResponseBody().single();
Object object = mono.block();
@@ -430,7 +430,7 @@ class SleuthSpanCreatorAspectWebFlux {
public void shouldCreateNewSpanInWebFlux() {
setup();
Mono<Object> mono = webClient.get().uri("/test/newSpan1").exchange()
Mono<Object> mono = this.webClient.get().uri("/test/newSpan1").exchange()
.returnResult(Object.class).getResponseBody().single();
Object object = mono.block();
@@ -450,7 +450,7 @@ class SleuthSpanCreatorAspectWebFlux {
public void shouldCreateNewSpanInWebFluxInSubscriberContext() {
setup();
Mono<Object> mono = webClient.get().uri("/test/newSpan2").exchange()
Mono<Object> mono = this.webClient.get().uri("/test/newSpan2").exchange()
.returnResult(Object.class).getResponseBody().single();
Object object = mono.block();
@@ -471,7 +471,7 @@ class SleuthSpanCreatorAspectWebFlux {
public void shouldSetupCorrectSpanInHttpTrace() {
setup();
Mono<Object> mono = webClient.get().uri("/test/ping").exchange()
Mono<Object> mono = this.webClient.get().uri("/test/ping").exchange()
.returnResult(Object.class).getResponseBody().single();
Object object = mono.block();
@@ -485,7 +485,7 @@ class SleuthSpanCreatorAspectWebFlux {
then(spans.get(0).name()).isEqualTo("get /test/ping");
then(this.repository.getSpan()).isNotNull();
then(spans.get(0).id()).isEqualTo(toHexString(newSpanId))
.isEqualTo(repository.getSpan().context().traceIdString());
.isEqualTo(this.repository.getSpan().context().traceIdString());
then(this.tracer.currentSpan()).isNull();
});
}
@@ -537,14 +537,14 @@ class TestBean {
@ContinueSpan
public Mono<Long> continueSpanInTraceContext() {
log.info("Continue");
Long span = tracer.currentSpan().context().spanId();
Long span = this.tracer.currentSpan().context().spanId();
return Mono.defer(() -> Mono.just(span));
}
@NewSpan(name = "newSpanInTraceContext")
public Mono<Long> newSpanInTraceContext() {
log.info("New Span in Trace Context");
return Mono.defer(() -> Mono.just(tracer.currentSpan().context().spanId()));
return Mono.defer(() -> Mono.just(this.tracer.currentSpan().context().spanId()));
}
@NewSpan(name = "newSpanInSubscriberContext")
@@ -553,7 +553,7 @@ class TestBean {
return Mono.subscriberContext()
.doOnSuccess(context -> log.info("New Span in deferred Trace Context"))
.flatMap(context -> Mono
.defer(() -> Mono.just(tracer.currentSpan().context().spanId())));
.defer(() -> Mono.just(this.tracer.currentSpan().context().spanId())));
}
}

View File

@@ -40,10 +40,10 @@ public class GH846Tests {
@Test
public void doit() throws Exception {
int count = myBean.listAndCount();
int count = this.myBean.listAndCount();
Assert.assertEquals(
"Change detected in RestTemplate interceptor *after* @PostConstruct",
count, myBean.getCountAtPostConstruct());
count, this.myBean.getCountAtPostConstruct());
}
@EnableAutoConfiguration
@@ -72,19 +72,19 @@ public class GH846Tests {
@PostConstruct
public void init() {
countAtPostConstruct = listAndCount();
this.countAtPostConstruct = listAndCount();
}
public int listAndCount() {
for (ClientHttpRequestInterceptor interceptor : restTemplate
for (ClientHttpRequestInterceptor interceptor : this.restTemplate
.getInterceptors()) {
System.out.println(interceptor);
}
return restTemplate.getInterceptors().size();
return this.restTemplate.getInterceptors().size();
}
public int getCountAtPostConstruct() {
return countAtPostConstruct;
return this.countAtPostConstruct;
}
}

View File

@@ -102,7 +102,7 @@ public class MultipleAsyncRestTemplateTests {
Span span = this.tracer.nextSpan().name("foo");
try (Tracer.SpanInScope ws = this.tracer.withSpanInScope(span.start())) {
String result = this.asyncRestTemplate
.getForEntity("http://localhost:" + port + "/foo", String.class).get()
.getForEntity("http://localhost:" + this.port + "/foo", String.class).get()
.getBody();
then(span.context().traceIdString()).isEqualTo(result);
}

View File

@@ -125,7 +125,7 @@ class CustomExceptionHandler extends ResponseEntityExceptionHandler {
}
private void reportErrorSpan(String message) {
Span span = tracer.tracer().currentSpan();
Span span = this.tracer.tracer().currentSpan();
span.annotate("ERROR: " + message);
span.tag("custom", "tag");
logger.info("Foo");
@@ -156,7 +156,7 @@ class ExceptionResponse {
}
public String getErrorCode() {
return errorCode;
return this.errorCode;
}
public void setErrorCode(String errorCode) {
@@ -164,7 +164,7 @@ class ExceptionResponse {
}
public String getErrorMessage() {
return errorMessage;
return this.errorMessage;
}
public void setErrorMessage(String errorMessage) {
@@ -172,7 +172,7 @@ class ExceptionResponse {
}
public HttpStatus getHttpStatus() {
return httpStatus;
return this.httpStatus;
}
public void setHttpStatus(HttpStatus httpStatus) {
@@ -180,7 +180,7 @@ class ExceptionResponse {
}
public String getPath() {
return path;
return this.path;
}
public void setPath(String path) {
@@ -188,7 +188,7 @@ class ExceptionResponse {
}
public Long getEpochTime() {
return epochTime;
return this.epochTime;
}
public void setEpochTime(Long epochTime) {

View File

@@ -82,7 +82,7 @@ public class FeignRetriesTests {
Client client = (request, options) -> {
throw new IOException();
};
String url = "http://localhost:" + server.getPort();
String url = "http://localhost:" + this.server.getPort();
TestInterface api = Feign.builder()
.client(new TracingFeignClient(this.httpTracing, client))
@@ -98,7 +98,7 @@ public class FeignRetriesTests {
@Test
public void testRetriedWhenRequestEventuallyIsSent() throws Exception {
String url = "http://localhost:" + server.getPort();
String url = "http://localhost:" + this.server.getPort();
final AtomicInteger atomicInteger = new AtomicInteger();
// Client to simulate a retry scenario
final Client client = (request, options) -> {

View File

@@ -92,7 +92,7 @@ class SleuthSampleApplication {
@RequestMapping("/callhome")
public String callHome() {
LOG.info("calling home");
return restTemplate.getForObject("http://localhost:" + port(), String.class);
return this.restTemplate.getForObject("http://localhost:" + port(), String.class);
}
private int port() {
@@ -109,7 +109,7 @@ class ParticipantsBean {
@HystrixCommand(fallbackMethod = "defaultParticipants")
public List<Object> getParticipants(String raceId) {
return participantsClient.getParticipants(raceId);
return this.participantsClient.getParticipants(raceId);
}
public List<Object> defaultParticipants(String raceId) {

View File

@@ -149,12 +149,12 @@ class SleuthTestController {
@RequestMapping("/test-ok")
public String ok() throws InterruptedException, ExecutionException {
return myFeignClient.ok();
return this.myFeignClient.ok();
}
@RequestMapping("/test-not-ok")
public String notOk() throws InterruptedException, ExecutionException {
return myFeignClient.exp();
return this.myFeignClient.exp();
}
}

View File

@@ -191,7 +191,7 @@ class CustomConfig {
public Exception decode(String methodKey, Response response) {
this.feignComponentAsserter.executedComponents.put(ErrorDecoder.class, true);
if (response.status() == 409) {
return new RetryableException("Article not Ready", new Date());
return new RetryableException("Article not Ready", Request.HttpMethod.GET, new Date());
}
else {
return super.decode(methodKey, response);
@@ -262,12 +262,12 @@ class SleuthTestController {
@RequestMapping("/test-ok")
public String ok() throws InterruptedException, ExecutionException {
return myFeignClient.ok();
return this.myFeignClient.ok();
}
@RequestMapping("/test-not-ok")
public String notOk() throws InterruptedException, ExecutionException {
return myFeignClient.exp();
return this.myFeignClient.exp();
}
}

View File

@@ -139,7 +139,7 @@ class DemoController {
@RequestMapping(value = "/hello/{name}")
public String getHello(@PathVariable("name") String name) {
return myNameRemote.getName(name) + " foo";
return this.myNameRemote.getName(name) + " foo";
}
@RequestMapping(value = "/name/{name}")

View File

@@ -98,8 +98,8 @@ public class FeignClientServerErrorTests {
@Test
public void shouldCloseSpanOnInternalServerError() {
try (Tracer.SpanInScope ws = tracer
.withSpanInScope(tracer.nextSpan().name("foo").start())) {
try (Tracer.SpanInScope ws = this.tracer
.withSpanInScope(this.tracer.nextSpan().name("foo").start())) {
log.info("sending a request");
this.feignInterface.internalError();
fail("Must throw an exception");
@@ -121,8 +121,8 @@ public class FeignClientServerErrorTests {
@Test
public void shouldCloseSpanOnNotFound() {
try (Tracer.SpanInScope ws = tracer
.withSpanInScope(tracer.nextSpan().name("foo").start())) {
try (Tracer.SpanInScope ws = this.tracer
.withSpanInScope(this.tracer.nextSpan().name("foo").start())) {
log.info("sending a request");
this.feignInterface.notFound();
fail("Must throw an exception");
@@ -144,8 +144,8 @@ public class FeignClientServerErrorTests {
@Test
public void shouldCloseSpanOnOk() {
try (Tracer.SpanInScope ws = tracer
.withSpanInScope(tracer.nextSpan().name("foo").start())) {
try (Tracer.SpanInScope ws = this.tracer
.withSpanInScope(this.tracer.nextSpan().name("foo").start())) {
log.info("sending a request");
this.feignInterface.ok();
}
@@ -166,8 +166,8 @@ public class FeignClientServerErrorTests {
@Test
public void shouldCloseSpanOnOkWithCustomFeignConfiguration() {
try (Tracer.SpanInScope ws = tracer
.withSpanInScope(tracer.nextSpan().name("foo").start())) {
try (Tracer.SpanInScope ws = this.tracer
.withSpanInScope(this.tracer.nextSpan().name("foo").start())) {
log.info("sending a request");
this.customConfFeignInterface.ok();
fail("Must throw an exception");
@@ -189,8 +189,8 @@ public class FeignClientServerErrorTests {
@Test
public void shouldCloseSpanOnNotFoundWithCustomFeignConfiguration() {
try (Tracer.SpanInScope ws = tracer
.withSpanInScope(tracer.nextSpan().name("foo").start())) {
try (Tracer.SpanInScope ws = this.tracer
.withSpanInScope(this.tracer.nextSpan().name("foo").start())) {
log.info("sending a request");
this.customConfFeignInterface.notFound();
fail("Must throw an exception");

View File

@@ -288,7 +288,7 @@ public class WebClientTests {
try (Tracer.SpanInScope ws = this.tracer.withSpanInScope(span)) {
HttpClientResponse response = this.nettyHttpClient.get()
.uri("http://localhost:" + port).response().block();
.uri("http://localhost:" + this.port).response().block();
then(response).isNotNull();
}
@@ -311,7 +311,7 @@ public class WebClientTests {
try (Tracer.SpanInScope ws = this.tracer.withSpanInScope(span)) {
String response = this.httpClientBuilder.build().execute(
new HttpGet("http://localhost:" + port), new BasicResponseHandler());
new HttpGet("http://localhost:" + this.port), new BasicResponseHandler());
then(response).isNotEmpty();
}
@@ -332,7 +332,7 @@ public class WebClientTests {
try (Tracer.SpanInScope ws = this.tracer.withSpanInScope(span)) {
client.start();
Future<HttpResponse> future = client.execute(
new HttpGet("http://localhost:" + port),
new HttpGet("http://localhost:" + this.port),
new FutureCallback<HttpResponse>() {
@Override
public void completed(HttpResponse result) {
@@ -573,7 +573,7 @@ public class WebClientTests {
}
public boolean isExecuted() {
return executed;
return this.executed;
}
}

View File

@@ -127,7 +127,7 @@ class TraceCheckingSpanFilter extends ZuulFilter {
public Object run() {
long trace = this.tracer.tracer().currentSpan().context().traceId();
Integer integer = this.counter.getOrDefault(trace, 0);
counter.put(trace, integer + 1);
this.counter.put(trace, integer + 1);
return null;
}

View File

@@ -168,7 +168,7 @@ public class DefaultEndpointLocatorConfigurationTest {
@Test
public void portDefaultsTo8080() throws UnknownHostException {
DefaultEndpointLocator locator = new DefaultEndpointLocator(null,
new ServerProperties(), environment, new ZipkinProperties(),
new ServerProperties(), this.environment, new ZipkinProperties(),
localAddress(ADDRESS1234));
assertThat(locator.local().port()).isEqualTo(8080);
@@ -180,7 +180,7 @@ public class DefaultEndpointLocatorConfigurationTest {
properties.setPort(1234);
DefaultEndpointLocator locator = new DefaultEndpointLocator(null, properties,
environment, new ZipkinProperties(), localAddress(ADDRESS1234));
this.environment, new ZipkinProperties(), localAddress(ADDRESS1234));
assertThat(locator.local().port()).isEqualTo(1234);
}
@@ -188,7 +188,7 @@ public class DefaultEndpointLocatorConfigurationTest {
@Test
public void portDefaultsToLocalhost() throws UnknownHostException {
DefaultEndpointLocator locator = new DefaultEndpointLocator(null,
new ServerProperties(), environment, new ZipkinProperties(),
new ServerProperties(), this.environment, new ZipkinProperties(),
localAddress(ADDRESS1234));
assertThat(locator.local().ipv4()).isEqualTo("1.2.3.4");
@@ -200,7 +200,7 @@ public class DefaultEndpointLocatorConfigurationTest {
properties.setAddress(InetAddress.getByAddress(ADDRESS1234));
DefaultEndpointLocator locator = new DefaultEndpointLocator(null, properties,
environment, new ZipkinProperties(),
this.environment, new ZipkinProperties(),
localAddress(new byte[] { 4, 4, 4, 4 }));
assertThat(locator.local().ipv4()).isEqualTo("1.2.3.4");
@@ -213,7 +213,7 @@ public class DefaultEndpointLocatorConfigurationTest {
zipkinProperties.getService().setName("foo");
DefaultEndpointLocator locator = new DefaultEndpointLocator(null, properties,
environment, zipkinProperties, localAddress(ADDRESS1234));
this.environment, zipkinProperties, localAddress(ADDRESS1234));
assertThat(locator.local().serviceName()).isEqualTo("foo");
}
@@ -224,7 +224,7 @@ public class DefaultEndpointLocatorConfigurationTest {
properties.setPort(-1);
DefaultEndpointLocator locator = new DefaultEndpointLocator(null, properties,
environment, new ZipkinProperties(), localAddress(ADDRESS1234));
this.environment, new ZipkinProperties(), localAddress(ADDRESS1234));
assertThat(locator.local().port()).isEqualTo(8080);
}

View File

@@ -61,125 +61,125 @@ public class ZipkinAutoConfigurationTests {
@After
public void close() {
if (context != null) {
context.close();
if (this.context != null) {
this.context.close();
}
}
@Test
public void defaultsToV2Endpoint() throws Exception {
context = new AnnotationConfigApplicationContext();
environment().setProperty("spring.zipkin.base-url", server.url("/").toString());
context.register(ZipkinAutoConfiguration.class,
this.context = new AnnotationConfigApplicationContext();
environment().setProperty("spring.zipkin.base-url", this.server.url("/").toString());
this.context.register(ZipkinAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class, TraceAutoConfiguration.class,
Config.class);
context.refresh();
Span span = context.getBean(Tracing.class).tracer().nextSpan().name("foo")
this.context.refresh();
Span span = this.context.getBean(Tracing.class).tracer().nextSpan().name("foo")
.tag("foo", "bar").start();
span.finish();
Awaitility.await()
.untilAsserted(() -> then(server.getRequestCount()).isGreaterThan(0));
RecordedRequest request = server.takeRequest();
.untilAsserted(() -> then(this.server.getRequestCount()).isGreaterThan(0));
RecordedRequest request = this.server.takeRequest();
then(request.getPath()).isEqualTo("/api/v2/spans");
then(request.getBody().readUtf8()).contains("localEndpoint");
}
private MockEnvironment environment() {
context.setEnvironment(environment);
return environment;
this.context.setEnvironment(this.environment);
return this.environment;
}
@Test
public void encoderDirectsEndpoint() throws Exception {
context = new AnnotationConfigApplicationContext();
environment().setProperty("spring.zipkin.base-url", server.url("/").toString());
this.context = new AnnotationConfigApplicationContext();
environment().setProperty("spring.zipkin.base-url", this.server.url("/").toString());
environment().setProperty("spring.zipkin.encoder", "JSON_V1");
context.register(ZipkinAutoConfiguration.class,
this.context.register(ZipkinAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class, TraceAutoConfiguration.class,
Config.class);
context.refresh();
Span span = context.getBean(Tracing.class).tracer().nextSpan().name("foo")
this.context.refresh();
Span span = this.context.getBean(Tracing.class).tracer().nextSpan().name("foo")
.tag("foo", "bar").start();
span.finish();
Awaitility.await()
.untilAsserted(() -> then(server.getRequestCount()).isGreaterThan(0));
RecordedRequest request = server.takeRequest();
.untilAsserted(() -> then(this.server.getRequestCount()).isGreaterThan(0));
RecordedRequest request = this.server.takeRequest();
then(request.getPath()).isEqualTo("/api/v1/spans");
then(request.getBody().readUtf8()).contains("binaryAnnotations");
}
@Test
public void overrideRabbitMQQueue() throws Exception {
context = new AnnotationConfigApplicationContext();
this.context = new AnnotationConfigApplicationContext();
environment().setProperty("spring.zipkin.rabbitmq.queue", "zipkin2");
context.register(PropertyPlaceholderAutoConfiguration.class,
this.context.register(PropertyPlaceholderAutoConfiguration.class,
RabbitAutoConfiguration.class, ZipkinAutoConfiguration.class);
context.refresh();
this.context.refresh();
then(context.getBean(Sender.class)).isInstanceOf(RabbitMQSender.class);
then(this.context.getBean(Sender.class)).isInstanceOf(RabbitMQSender.class);
context.close();
this.context.close();
}
@Test
public void overrideKafkaTopic() throws Exception {
context = new AnnotationConfigApplicationContext();
this.context = new AnnotationConfigApplicationContext();
environment().setProperty("spring.zipkin.kafka.topic", "zipkin2");
environment().setProperty("spring.zipkin.sender.type", "kafka");
context.register(PropertyPlaceholderAutoConfiguration.class,
this.context.register(PropertyPlaceholderAutoConfiguration.class,
KafkaAutoConfiguration.class, ZipkinAutoConfiguration.class);
context.refresh();
this.context.refresh();
then(context.getBean(Sender.class)).isInstanceOf(KafkaSender.class);
then(this.context.getBean(Sender.class)).isInstanceOf(KafkaSender.class);
context.close();
this.context.close();
}
@Test
public void canOverrideBySender() throws Exception {
context = new AnnotationConfigApplicationContext();
this.context = new AnnotationConfigApplicationContext();
environment().setProperty("spring.zipkin.sender.type", "web");
context.register(PropertyPlaceholderAutoConfiguration.class,
this.context.register(PropertyPlaceholderAutoConfiguration.class,
RabbitAutoConfiguration.class, KafkaAutoConfiguration.class,
ZipkinAutoConfiguration.class);
context.refresh();
this.context.refresh();
then(context.getBean(Sender.class).getClass().getName())
then(this.context.getBean(Sender.class).getClass().getName())
.contains("RestTemplateSender");
context.close();
this.context.close();
}
@Test
public void canOverrideBySenderAndIsCaseInsensitive() throws Exception {
context = new AnnotationConfigApplicationContext();
this.context = new AnnotationConfigApplicationContext();
environment().setProperty("spring.zipkin.sender.type", "WEB");
context.register(PropertyPlaceholderAutoConfiguration.class,
this.context.register(PropertyPlaceholderAutoConfiguration.class,
RabbitAutoConfiguration.class, KafkaAutoConfiguration.class,
ZipkinAutoConfiguration.class);
context.refresh();
this.context.refresh();
then(context.getBean(Sender.class).getClass().getName())
then(this.context.getBean(Sender.class).getClass().getName())
.contains("RestTemplateSender");
context.close();
this.context.close();
}
@Test
public void rabbitWinsWhenKafkaPresent() throws Exception {
context = new AnnotationConfigApplicationContext();
context.register(PropertyPlaceholderAutoConfiguration.class,
this.context = new AnnotationConfigApplicationContext();
this.context.register(PropertyPlaceholderAutoConfiguration.class,
RabbitAutoConfiguration.class, KafkaAutoConfiguration.class,
ZipkinAutoConfiguration.class);
context.refresh();
this.context.refresh();
then(context.getBean(Sender.class)).isInstanceOf(RabbitMQSender.class);
then(this.context.getBean(Sender.class)).isInstanceOf(RabbitMQSender.class);
context.close();
this.context.close();
}
@Configuration

View File

@@ -47,30 +47,30 @@ public class RestTemplateSenderTest {
@Rule
public MockWebServer server = new MockWebServer();
String endpoint = server.url("/api/v2/spans").toString();
String endpoint = this.server.url("/api/v2/spans").toString();
RestTemplateSender sender = new RestTemplateSender(new RestTemplate(), endpoint,
RestTemplateSender sender = new RestTemplateSender(new RestTemplate(), this.endpoint,
JSON_V2);
/** Tests that json is not manipulated as a side-effect of using rest template. */
@Test
public void jsonIsNormal() throws Exception {
server.enqueue(new MockResponse());
this.server.enqueue(new MockResponse());
send(SPAN).execute();
assertThat(server.takeRequest().getBody().readUtf8())
assertThat(this.server.takeRequest().getBody().readUtf8())
.isEqualTo("[" + new String(JSON_V2.encode(SPAN), "UTF-8") + "]");
}
@Test
public void proto3() throws Exception {
server.enqueue(new MockResponse());
sender = new RestTemplateSender(new RestTemplate(), endpoint, PROTO3);
this.server.enqueue(new MockResponse());
this.sender = new RestTemplateSender(new RestTemplate(), this.endpoint, PROTO3);
send(SPAN).execute();
RecordedRequest request = server.takeRequest();
RecordedRequest request = this.server.takeRequest();
assertThat(request.getHeader("Content-Type")).isEqualTo("application/x-protobuf");
// proto3 encoding of ListOfSpan is simply a repeated span entry
@@ -79,9 +79,9 @@ public class RestTemplateSenderTest {
}
Call<Void> send(Span... spans) {
SpanBytesEncoder bytesEncoder = sender.encoding() == Encoding.JSON
SpanBytesEncoder bytesEncoder = this.sender.encoding() == Encoding.JSON
? SpanBytesEncoder.JSON_V2 : SpanBytesEncoder.PROTO3;
return sender
return this.sender
.sendSpans(Stream.of(spans).map(bytesEncoder::encode).collect(toList()));
}