From 8c82c8aa9f1eb1029365408543dcd80f413a6a38 Mon Sep 17 00:00:00 2001 From: Marcin Grzejszczak Date: Thu, 7 Feb 2019 13:12:21 +0100 Subject: [PATCH] Revert "Fixed the build" This reverts commit 3107d3f3 --- .../annotation/NoOpTagValueResolver.java | 2 +- .../annotation/SpanTagAnnotationHandler.java | 2 +- .../sleuth/annotation/TagValueResolver.java | 3 +- .../messaging/TracingChannelInterceptor.java | 10 ++-- .../client/HttpClientBeanPostProcessor.java | 2 + .../annotation/NoOpTagValueResolverTests.java | 2 +- .../SleuthSpanCreatorAspectFluxTests.java | 56 ++++++++++--------- .../SleuthSpanCreatorAspectMonoTests.java | 55 +++++++++--------- .../SleuthSpanCreatorAspectNegativeTests.java | 8 +-- .../SleuthSpanCreatorAspectTests.java | 50 ++++++++--------- .../SpanTagAnnotationHandlerTests.java | 10 ++-- ...TraceableScheduledExecutorServiceTest.java | 34 ++++++----- .../grpc/stubs/HelloServiceOuterClass.java | 5 +- .../feign/issues/issue307/Issue307Tests.java | 2 +- ...ZipkinRestTemplateSenderConfiguration.java | 6 +- 15 files changed, 132 insertions(+), 115 deletions(-) diff --git a/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/annotation/NoOpTagValueResolver.java b/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/annotation/NoOpTagValueResolver.java index f8bf53dbd..603d47589 100644 --- a/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/annotation/NoOpTagValueResolver.java +++ b/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/annotation/NoOpTagValueResolver.java @@ -25,7 +25,7 @@ package org.springframework.cloud.sleuth.annotation; class NoOpTagValueResolver implements TagValueResolver { @Override - public String resolve() { + public String resolve(Object parameter) { return null; } diff --git a/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/annotation/SpanTagAnnotationHandler.java b/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/annotation/SpanTagAnnotationHandler.java index 323c849a8..8d6b51253 100644 --- a/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/annotation/SpanTagAnnotationHandler.java +++ b/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/annotation/SpanTagAnnotationHandler.java @@ -151,7 +151,7 @@ class SpanTagAnnotationHandler { if (annotation.resolver() != NoOpTagValueResolver.class) { TagValueResolver tagValueResolver = this.beanFactory .getBean(annotation.resolver()); - return tagValueResolver.resolve(); + return tagValueResolver.resolve(argument); } else if (StringUtils.hasText(annotation.expression())) { return this.beanFactory.getBean(TagValueExpressionResolver.class) diff --git a/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/annotation/TagValueResolver.java b/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/annotation/TagValueResolver.java index 1a682fd23..32d1690fe 100644 --- a/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/annotation/TagValueResolver.java +++ b/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/annotation/TagValueResolver.java @@ -26,8 +26,9 @@ public interface TagValueResolver { /** * Returns the tag value for the given parameter. + * @param parameter - parameter annotated with {@link SpanTag} * @return the value of the tag */ - String resolve(); + String resolve(Object parameter); } diff --git a/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/messaging/TracingChannelInterceptor.java b/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/messaging/TracingChannelInterceptor.java index 9e03f4083..e8c720a0b 100644 --- a/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/messaging/TracingChannelInterceptor.java +++ b/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/messaging/TracingChannelInterceptor.java @@ -141,7 +141,7 @@ public final class TracingChannelInterceptor extends ChannelInterceptorAdapter headers.setImmutable(); Span result = this.tracer.nextSpan(extracted); if (extracted.context() == null && !result.isNoop()) { - addTags(result, null); + addTags(message, result, null); } if (log.isDebugEnabled()) { log.debug("Created a new span " + result); @@ -167,7 +167,7 @@ public final class TracingChannelInterceptor extends ChannelInterceptorAdapter if (!span.isNoop()) { span.kind(Span.Kind.PRODUCER).name("send").start(); span.remoteServiceName(REMOTE_SERVICE_NAME); - addTags(span, channel); + addTags(message, span, channel); } if (log.isDebugEnabled()) { log.debug("Created a new span in pre send" + span); @@ -253,7 +253,7 @@ public final class TracingChannelInterceptor extends ChannelInterceptorAdapter if (!span.isNoop()) { span.kind(Span.Kind.CONSUMER).name("receive").start(); span.remoteServiceName(REMOTE_SERVICE_NAME); - addTags(span, channel); + addTags(message, span, channel); } if (log.isDebugEnabled()) { log.debug("Created a new span in post receive " + span); @@ -292,7 +292,7 @@ public final class TracingChannelInterceptor extends ChannelInterceptorAdapter if (!consumerSpan.isNoop()) { consumerSpan.kind(Span.Kind.CONSUMER).start(); consumerSpan.remoteServiceName(REMOTE_SERVICE_NAME); - addTags(consumerSpan, channel); + addTags(message, consumerSpan, channel); consumerSpan.finish(); } // create and scope a span for the message processor @@ -331,7 +331,7 @@ public final class TracingChannelInterceptor extends ChannelInterceptorAdapter /** * When an upstream context was not present, lookup keys are unlikely added */ - void addTags(SpanCustomizer result, MessageChannel channel) { + void addTags(Message message, SpanCustomizer result, MessageChannel channel) { // TODO topic etc if (channel != null) { result.tag("channel", messageChannelName(channel)); diff --git a/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/web/client/HttpClientBeanPostProcessor.java b/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/web/client/HttpClientBeanPostProcessor.java index 800d47335..f25cd9a76 100644 --- a/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/web/client/HttpClientBeanPostProcessor.java +++ b/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/web/client/HttpClientBeanPostProcessor.java @@ -106,6 +106,8 @@ class HttpClientBeanPostProcessor implements BeanPostProcessor { HttpTracing httpTracing; + Tracer tracer; + HttpClientHandler handler; TraceContext.Injector injector; diff --git a/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/annotation/NoOpTagValueResolverTests.java b/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/annotation/NoOpTagValueResolverTests.java index e8c9aa55e..aa7dd19f6 100644 --- a/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/annotation/NoOpTagValueResolverTests.java +++ b/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/annotation/NoOpTagValueResolverTests.java @@ -27,7 +27,7 @@ public class NoOpTagValueResolverTests { @Test public void should_return_null() throws Exception { - then(new NoOpTagValueResolver().resolve()).isNull(); + then(new NoOpTagValueResolver().resolve("")).isNull(); } } \ No newline at end of file diff --git a/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/annotation/SleuthSpanCreatorAspectFluxTests.java b/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/annotation/SleuthSpanCreatorAspectFluxTests.java index e46a4f034..720331509 100644 --- a/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/annotation/SleuthSpanCreatorAspectFluxTests.java +++ b/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/annotation/SleuthSpanCreatorAspectFluxTests.java @@ -131,7 +131,7 @@ public class SleuthSpanCreatorAspectFluxTests { @Test public void shouldCreateSpanWithTagWhenAnnotationOnInterfaceMethod() { // tag::execution[] - Flux flux = this.testBean.testMethod5(); + Flux flux = this.testBean.testMethod5("test"); // end::execution[] verifyNoSpansUntilFluxComplete(flux); @@ -148,7 +148,7 @@ public class SleuthSpanCreatorAspectFluxTests { @Test public void shouldCreateSpanWithTagWhenAnnotationOnClassMethod() { - Flux flux = this.testBean.testMethod6(); + Flux flux = this.testBean.testMethod6("test"); verifyNoSpansUntilFluxComplete(flux); @@ -164,7 +164,7 @@ public class SleuthSpanCreatorAspectFluxTests { @Test public void shouldCreateSpanWithLogWhenAnnotationOnInterfaceMethod() { - Flux flux = this.testBean.testMethod8(); + Flux flux = this.testBean.testMethod8("test"); verifyNoSpansUntilFluxComplete(flux); @@ -179,7 +179,7 @@ public class SleuthSpanCreatorAspectFluxTests { @Test public void shouldCreateSpanWithLogWhenAnnotationOnClassMethod() { - Flux flux = this.testBean.testMethod9(); + Flux flux = this.testBean.testMethod9("test"); verifyNoSpansUntilFluxComplete(flux); @@ -199,7 +199,7 @@ public class SleuthSpanCreatorAspectFluxTests { Span span = this.tracer.nextSpan().name("foo"); try (Tracer.SpanInScope ws = this.tracer.withSpanInScope(span.start())) { - Flux flux = this.testBean.testMethod10(); + Flux flux = this.testBean.testMethod10("test"); verifyNoSpansUntilFluxComplete(flux); } @@ -222,7 +222,7 @@ public class SleuthSpanCreatorAspectFluxTests { @Test public void shouldStartAndCloseSpanOnContinueSpanIfSpanNotSet() { - Flux flux = this.testBean.testMethod10(); + Flux flux = this.testBean.testMethod10("test"); verifyNoSpansUntilFluxComplete(flux); Awaitility.await().untilAsserted(() -> { @@ -243,7 +243,7 @@ public class SleuthSpanCreatorAspectFluxTests { Span span = this.tracer.nextSpan().name("foo"); try (Tracer.SpanInScope ws = this.tracer.withSpanInScope(span.start())) { - Flux flux = this.testBean.testMethod10_v2(); + Flux flux = this.testBean.testMethod10_v2("test"); verifyNoSpansUntilFluxComplete(flux); } @@ -270,7 +270,7 @@ public class SleuthSpanCreatorAspectFluxTests { try (Tracer.SpanInScope ws = this.tracer.withSpanInScope(span.start())) { // tag::continue_span_execution[] - Flux flux = this.testBean.testMethod11(); + Flux flux = this.testBean.testMethod11("test"); // end::continue_span_execution[] verifyNoSpansUntilFluxComplete(flux); } @@ -296,7 +296,7 @@ public class SleuthSpanCreatorAspectFluxTests { @Test public void shouldAddErrorTagWhenExceptionOccurredInNewSpan() { try { - Flux flux = this.testBean.testMethod12(); + Flux flux = this.testBean.testMethod12("test"); then(this.reporter.getSpans()).isEmpty(); @@ -428,38 +428,38 @@ public class SleuthSpanCreatorAspectFluxTests { // tag::custom_name_and_tag_on_annotated_method[] @NewSpan(name = "customNameOnTestMethod5") - Flux testMethod5(); + Flux testMethod5(@SpanTag("testTag") String param); // end::custom_name_and_tag_on_annotated_method[] - Flux testMethod6(); + Flux testMethod6(String test); Flux testMethod7(); @NewSpan(name = "customNameOnTestMethod8") - Flux testMethod8(); + Flux testMethod8(String param); @NewSpan(name = "testMethod9") - Flux testMethod9(); + Flux testMethod9(String param); @ContinueSpan(log = "customTest") - Flux testMethod10(); + Flux testMethod10(@SpanTag(value = "testTag10") String param); @ContinueSpan(log = "customTest") - Flux testMethod10_v2(); + Flux testMethod10_v2(@SpanTag(key = "testTag10") String param); // tag::continue_span[] @ContinueSpan(log = "testMethod11") - Flux testMethod11(); + Flux testMethod11(@SpanTag("testTag11") String param); // end::continue_span[] @NewSpan - Flux testMethod12(); + Flux testMethod12(@SpanTag("testTag12") String param); @ContinueSpan(log = "testMethod13") Flux testMethod13(); @ContinueSpan - Flux testMethod14(); + Flux testMethod14(String param); @NewSpan(name = "spanInTraceContext") Flux newSpanInTraceContext(); @@ -527,13 +527,13 @@ public class SleuthSpanCreatorAspectFluxTests { } @Override - public Flux testMethod5() { + public Flux testMethod5(String test) { return this.testFlux; } @NewSpan(name = "customNameOnTestMethod6") @Override - public Flux testMethod6() { + public Flux testMethod6(@SpanTag("testTag6") String test) { return this.testFlux; } @@ -543,34 +543,36 @@ public class SleuthSpanCreatorAspectFluxTests { } @Override - public Flux testMethod8() { + public Flux testMethod8(String param) { return this.testFlux; } @NewSpan(name = "customNameOnTestMethod9") @Override - public Flux testMethod9() { + public Flux testMethod9(String param) { return this.testFlux; } @Override - public Flux testMethod10() { + public Flux testMethod10( + @SpanTag(value = "customTestTag10") String param) { return this.testFlux; } @Override - public Flux testMethod10_v2() { + public Flux testMethod10_v2( + @SpanTag(key = "customTestTag10") String param) { return this.testFlux; } @ContinueSpan(log = "customTest") @Override - public Flux testMethod11() { + public Flux testMethod11(@SpanTag("customTestTag11") String param) { return this.testFlux; } @Override - public Flux testMethod12() { + public Flux testMethod12(String param) { return Flux .defer(() -> Flux.error(new RuntimeException("test exception 12"))); } @@ -582,7 +584,7 @@ public class SleuthSpanCreatorAspectFluxTests { } @Override - public Flux testMethod14() { + public Flux testMethod14(String param) { return Flux.just(TEST_STRING1, TEST_STRING2); } diff --git a/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/annotation/SleuthSpanCreatorAspectMonoTests.java b/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/annotation/SleuthSpanCreatorAspectMonoTests.java index cd2764146..4e61eba5d 100644 --- a/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/annotation/SleuthSpanCreatorAspectMonoTests.java +++ b/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/annotation/SleuthSpanCreatorAspectMonoTests.java @@ -44,12 +44,11 @@ import org.springframework.test.context.junit4.SpringRunner; import static org.assertj.core.api.BDDAssertions.then; import static org.springframework.cloud.sleuth.annotation.SleuthSpanCreatorAspectMonoTests.TestBean.TEST_STRING; -import static org.springframework.test.annotation.DirtiesContext.MethodMode.BEFORE_METHOD; import static reactor.core.publisher.Mono.just; @SpringBootTest(classes = SleuthSpanCreatorAspectMonoTests.TestConfiguration.class) @RunWith(SpringRunner.class) -@DirtiesContext(methodMode = BEFORE_METHOD) +@DirtiesContext public class SleuthSpanCreatorAspectMonoTests { @Autowired @@ -141,7 +140,7 @@ public class SleuthSpanCreatorAspectMonoTests { @Test public void shouldCreateSpanWithTagWhenAnnotationOnInterfaceMethod() { // tag::execution[] - Mono mono = this.testBean.testMethod5(); + Mono mono = this.testBean.testMethod5("test"); // end::execution[] then(this.reporter.getSpans()).isEmpty(); @@ -160,7 +159,7 @@ public class SleuthSpanCreatorAspectMonoTests { @Test public void shouldCreateSpanWithTagWhenAnnotationOnClassMethod() { - Mono mono = this.testBean.testMethod6(); + Mono mono = this.testBean.testMethod6("test"); then(this.reporter.getSpans()).isEmpty(); @@ -178,7 +177,7 @@ public class SleuthSpanCreatorAspectMonoTests { @Test public void shouldCreateSpanWithLogWhenAnnotationOnInterfaceMethod() { - Mono mono = this.testBean.testMethod8(); + Mono mono = this.testBean.testMethod8("test"); then(this.reporter.getSpans()).isEmpty(); @@ -195,7 +194,7 @@ public class SleuthSpanCreatorAspectMonoTests { @Test public void shouldCreateSpanWithLogWhenAnnotationOnClassMethod() { - Mono mono = this.testBean.testMethod9(); + Mono mono = this.testBean.testMethod9("test"); then(this.reporter.getSpans()).isEmpty(); @@ -217,7 +216,7 @@ public class SleuthSpanCreatorAspectMonoTests { Span span = this.tracer.nextSpan().name("foo"); try (Tracer.SpanInScope ws = this.tracer.withSpanInScope(span.start())) { - Mono mono = this.testBean.testMethod10(); + Mono mono = this.testBean.testMethod10("test"); then(this.reporter.getSpans()).isEmpty(); @@ -242,7 +241,7 @@ public class SleuthSpanCreatorAspectMonoTests { @Test public void shouldStartAndCloseSpanOnContinueSpanIfSpanNotSet() { - this.testBean.testMethod10().block(); + this.testBean.testMethod10("test").block(); Awaitility.await().untilAsserted(() -> { List spans = this.reporter.getSpans(); @@ -262,7 +261,7 @@ public class SleuthSpanCreatorAspectMonoTests { Span span = this.tracer.nextSpan().name("foo"); try (Tracer.SpanInScope ws = this.tracer.withSpanInScope(span.start())) { - Mono mono = this.testBean.testMethod10_v2(); + Mono mono = this.testBean.testMethod10_v2("test"); then(this.reporter.getSpans()).isEmpty(); @@ -291,7 +290,7 @@ public class SleuthSpanCreatorAspectMonoTests { try (Tracer.SpanInScope ws = this.tracer.withSpanInScope(span.start())) { // tag::continue_span_execution[] - Mono mono = this.testBean.testMethod11(); + Mono mono = this.testBean.testMethod11("test"); // end::continue_span_execution[] then(this.reporter.getSpans()).isEmpty(); @@ -319,7 +318,7 @@ public class SleuthSpanCreatorAspectMonoTests { @Test public void shouldAddErrorTagWhenExceptionOccurredInNewSpan() { try { - Mono mono = this.testBean.testMethod12(); + Mono mono = this.testBean.testMethod12("test"); then(this.reporter.getSpans()).isEmpty(); @@ -490,32 +489,32 @@ public class SleuthSpanCreatorAspectMonoTests { // tag::custom_name_and_tag_on_annotated_method[] @NewSpan(name = "customNameOnTestMethod5") - Mono testMethod5(); + Mono testMethod5(@SpanTag("testTag") String param); // end::custom_name_and_tag_on_annotated_method[] - Mono testMethod6(); + Mono testMethod6(String test); Mono testMethod7(); @NewSpan(name = "customNameOnTestMethod8") - Mono testMethod8(); + Mono testMethod8(String param); @NewSpan(name = "testMethod9") - Mono testMethod9(); + Mono testMethod9(String param); @ContinueSpan(log = "customTest") - Mono testMethod10(); + Mono testMethod10(@SpanTag(value = "testTag10") String param); @ContinueSpan(log = "customTest") - Mono testMethod10_v2(); + Mono testMethod10_v2(@SpanTag(key = "testTag10") String param); // tag::continue_span[] @ContinueSpan(log = "testMethod11") - Mono testMethod11(); + Mono testMethod11(@SpanTag("testTag11") String param); // end::continue_span[] @NewSpan - Mono testMethod12(); + Mono testMethod12(@SpanTag("testTag12") String param); @ContinueSpan(log = "testMethod13") Mono testMethod13(); @@ -565,13 +564,13 @@ public class SleuthSpanCreatorAspectMonoTests { } @Override - public Mono testMethod5() { + public Mono testMethod5(String test) { return TEST_MONO; } @NewSpan(name = "customNameOnTestMethod6") @Override - public Mono testMethod6() { + public Mono testMethod6(@SpanTag("testTag6") String test) { return TEST_MONO; } @@ -581,34 +580,36 @@ public class SleuthSpanCreatorAspectMonoTests { } @Override - public Mono testMethod8() { + public Mono testMethod8(String param) { return TEST_MONO; } @NewSpan(name = "customNameOnTestMethod9") @Override - public Mono testMethod9() { + public Mono testMethod9(String param) { return TEST_MONO; } @Override - public Mono testMethod10() { + public Mono testMethod10( + @SpanTag(value = "customTestTag10") String param) { return TEST_MONO; } @Override - public Mono testMethod10_v2() { + public Mono testMethod10_v2( + @SpanTag(key = "customTestTag10") String param) { return TEST_MONO; } @ContinueSpan(log = "customTest") @Override - public Mono testMethod11() { + public Mono testMethod11(@SpanTag("customTestTag11") String param) { return TEST_MONO; } @Override - public Mono testMethod12() { + public Mono testMethod12(String param) { return Mono .defer(() -> Mono.error(new RuntimeException("test exception 12"))); } diff --git a/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/annotation/SleuthSpanCreatorAspectNegativeTests.java b/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/annotation/SleuthSpanCreatorAspectNegativeTests.java index a7977e41f..27af6fccd 100644 --- a/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/annotation/SleuthSpanCreatorAspectNegativeTests.java +++ b/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/annotation/SleuthSpanCreatorAspectNegativeTests.java @@ -95,9 +95,9 @@ public class SleuthSpanCreatorAspectNegativeTests { void testMethod4(); @NewSpan(name = "testMethod5") - void testMethod5(); + void testMethod5(@SpanTag("testTag") String test); - void testMethod6(); + void testMethod6(String test); void testMethod7(); @@ -124,12 +124,12 @@ public class SleuthSpanCreatorAspectNegativeTests { } @Override - public void testMethod5() { + public void testMethod5(String test) { } @NewSpan(name = "testMethod6") @Override - public void testMethod6() { + public void testMethod6(@SpanTag("testTag6") String test) { } diff --git a/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/annotation/SleuthSpanCreatorAspectTests.java b/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/annotation/SleuthSpanCreatorAspectTests.java index a68079425..0212fe4f3 100644 --- a/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/annotation/SleuthSpanCreatorAspectTests.java +++ b/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/annotation/SleuthSpanCreatorAspectTests.java @@ -105,7 +105,7 @@ public class SleuthSpanCreatorAspectTests { @Test public void shouldCreateSpanWithTagWhenAnnotationOnInterfaceMethod() { // tag::execution[] - this.testBean.testMethod5(); + this.testBean.testMethod5("test"); // end::execution[] List spans = this.reporter.getSpans(); @@ -118,7 +118,7 @@ public class SleuthSpanCreatorAspectTests { @Test public void shouldCreateSpanWithTagWhenAnnotationOnClassMethod() { - this.testBean.testMethod6(); + this.testBean.testMethod6("test"); List spans = this.reporter.getSpans(); then(spans).hasSize(1); @@ -130,7 +130,7 @@ public class SleuthSpanCreatorAspectTests { @Test public void shouldCreateSpanWithLogWhenAnnotationOnInterfaceMethod() { - this.testBean.testMethod8(); + this.testBean.testMethod8("test"); List spans = this.reporter.getSpans(); then(spans).hasSize(1); @@ -141,7 +141,7 @@ public class SleuthSpanCreatorAspectTests { @Test public void shouldCreateSpanWithLogWhenAnnotationOnClassMethod() { - this.testBean.testMethod9(); + this.testBean.testMethod9("test"); List spans = this.reporter.getSpans(); then(spans).hasSize(1); @@ -157,7 +157,7 @@ public class SleuthSpanCreatorAspectTests { Span span = this.tracer.nextSpan().name("foo"); try (Tracer.SpanInScope ws = this.tracer.withSpanInScope(span.start())) { - this.testBean.testMethod10(); + this.testBean.testMethod10("test"); } finally { span.finish(); @@ -176,7 +176,7 @@ public class SleuthSpanCreatorAspectTests { @Test public void shouldStartAndCloseSpanOnContinueSpanIfSpanNotSet() { - this.testBean.testMethod10(); + this.testBean.testMethod10("test"); List spans = this.reporter.getSpans(); then(spans).hasSize(1); @@ -194,7 +194,7 @@ public class SleuthSpanCreatorAspectTests { Span span = this.tracer.nextSpan().name("foo"); try (Tracer.SpanInScope ws = this.tracer.withSpanInScope(span.start())) { - this.testBean.testMethod10_v2(); + this.testBean.testMethod10_v2("test"); } finally { span.finish(); @@ -217,7 +217,7 @@ public class SleuthSpanCreatorAspectTests { try (Tracer.SpanInScope ws = this.tracer.withSpanInScope(span.start())) { // tag::continue_span_execution[] - this.testBean.testMethod11(); + this.testBean.testMethod11("test"); // end::continue_span_execution[] } finally { @@ -240,7 +240,7 @@ public class SleuthSpanCreatorAspectTests { @Test public void shouldAddErrorTagWhenExceptionOccurredInNewSpan() { try { - this.testBean.testMethod12(); + this.testBean.testMethod12("test"); } catch (RuntimeException ignored) { } @@ -308,32 +308,32 @@ public class SleuthSpanCreatorAspectTests { // tag::custom_name_and_tag_on_annotated_method[] @NewSpan(name = "customNameOnTestMethod5") - void testMethod5(); + void testMethod5(@SpanTag("testTag") String param); // end::custom_name_and_tag_on_annotated_method[] - void testMethod6(); + void testMethod6(String test); void testMethod7(); @NewSpan(name = "customNameOnTestMethod8") - void testMethod8(); + void testMethod8(String param); @NewSpan(name = "testMethod9") - void testMethod9(); + void testMethod9(String param); @ContinueSpan(log = "customTest") - void testMethod10(); + void testMethod10(@SpanTag(value = "testTag10") String param); @ContinueSpan(log = "customTest") - void testMethod10_v2(); + void testMethod10_v2(@SpanTag(key = "testTag10") String param); // tag::continue_span[] @ContinueSpan(log = "testMethod11") - void testMethod11(); + void testMethod11(@SpanTag("testTag11") String param); // end::continue_span[] @NewSpan - void testMethod12(); + void testMethod12(@SpanTag("testTag12") String param); @ContinueSpan(log = "testMethod13") void testMethod13(); @@ -363,12 +363,12 @@ public class SleuthSpanCreatorAspectTests { } @Override - public void testMethod5() { + public void testMethod5(String test) { } @NewSpan(name = "customNameOnTestMethod6") @Override - public void testMethod6() { + public void testMethod6(@SpanTag("testTag6") String test) { } @@ -377,34 +377,34 @@ public class SleuthSpanCreatorAspectTests { } @Override - public void testMethod8() { + public void testMethod8(String param) { } @NewSpan(name = "customNameOnTestMethod9") @Override - public void testMethod9() { + public void testMethod9(String param) { } @Override - public void testMethod10() { + public void testMethod10(@SpanTag(value = "customTestTag10") String param) { } @Override - public void testMethod10_v2() { + public void testMethod10_v2(@SpanTag(key = "customTestTag10") String param) { } @ContinueSpan(log = "customTest") @Override - public void testMethod11() { + public void testMethod11(@SpanTag("customTestTag11") String param) { } @Override - public void testMethod12() { + public void testMethod12(String param) { throw new RuntimeException("test exception 12"); } diff --git a/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/annotation/SpanTagAnnotationHandlerTests.java b/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/annotation/SpanTagAnnotationHandlerTests.java index 4e9135862..94a613f97 100644 --- a/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/annotation/SpanTagAnnotationHandlerTests.java +++ b/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/annotation/SpanTagAnnotationHandlerTests.java @@ -103,19 +103,21 @@ public class SpanTagAnnotationHandlerTests { // tag::resolver_bean[] @NewSpan - public void getAnnotationForTagValueResolver() { + public void getAnnotationForTagValueResolver( + @SpanTag(key = "test", resolver = TagValueResolver.class) String test) { } // end::resolver_bean[] // tag::spel[] @NewSpan - public void getAnnotationForTagValueExpression() { + public void getAnnotationForTagValueExpression( + @SpanTag(key = "test", expression = "'hello' + ' characters'") String test) { } // end::spel[] // tag::toString[] @NewSpan - public void getAnnotationForArgumentToString() { + public void getAnnotationForArgumentToString(@SpanTag("test") Long param) { } // end::toString[] @@ -128,7 +130,7 @@ public class SpanTagAnnotationHandlerTests { // tag::custom_resolver[] @Bean(name = "myCustomTagValueResolver") public TagValueResolver tagValueResolver() { - return () -> "Value from myCustomTagValueResolver"; + return parameter -> "Value from myCustomTagValueResolver"; } // end::custom_resolver[] diff --git a/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/async/TraceableScheduledExecutorServiceTest.java b/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/async/TraceableScheduledExecutorServiceTest.java index 6ff8ba22b..2fdf8364c 100644 --- a/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/async/TraceableScheduledExecutorServiceTest.java +++ b/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/async/TraceableScheduledExecutorServiceTest.java @@ -71,7 +71,8 @@ public class TraceableScheduledExecutorServiceTest { this.traceableScheduledExecutorService.schedule(aRunnable(), 1L, TimeUnit.DAYS); then(this.scheduledExecutorService).should().schedule( - (Runnable) BDDMockito.argThat(matcher(instanceOf(TraceRunnable.class))), + BDDMockito.argThat( + matcher(Runnable.class, instanceOf(TraceRunnable.class))), anyLong(), any(TimeUnit.class)); } @@ -80,7 +81,8 @@ public class TraceableScheduledExecutorServiceTest { this.traceableScheduledExecutorService.schedule(aCallable(), 1L, TimeUnit.DAYS); then(this.scheduledExecutorService).should().schedule( - (Callable) BDDMockito.argThat(matcher(instanceOf(TraceCallable.class))), + BDDMockito.argThat( + matcher(Callable.class, instanceOf(TraceCallable.class))), anyLong(), any(TimeUnit.class)); } @@ -90,8 +92,9 @@ public class TraceableScheduledExecutorServiceTest { TimeUnit.DAYS); then(this.scheduledExecutorService).should().scheduleAtFixedRate( - BDDMockito.argThat(matcher(instanceOf(TraceRunnable.class))), anyLong(), - anyLong(), any(TimeUnit.class)); + BDDMockito.argThat( + matcher(Runnable.class, instanceOf(TraceRunnable.class))), + anyLong(), anyLong(), any(TimeUnit.class)); } @Test @@ -100,8 +103,9 @@ public class TraceableScheduledExecutorServiceTest { TimeUnit.DAYS); then(this.scheduledExecutorService).should().scheduleWithFixedDelay( - BDDMockito.argThat(matcher(instanceOf(TraceRunnable.class))), anyLong(), - anyLong(), any(TimeUnit.class)); + BDDMockito.argThat( + matcher(Runnable.class, instanceOf(TraceRunnable.class))), + anyLong(), anyLong(), any(TimeUnit.class)); } @Test @@ -111,7 +115,8 @@ public class TraceableScheduledExecutorServiceTest { this.traceableScheduledExecutorService.schedule(aRunnable(), 1L, TimeUnit.DAYS); then(this.scheduledExecutorService).should(never()).schedule( - (Runnable) BDDMockito.argThat(matcher(instanceOf(TraceRunnable.class))), + BDDMockito.argThat( + matcher(Runnable.class, instanceOf(TraceRunnable.class))), anyLong(), any(TimeUnit.class)); } @@ -122,7 +127,8 @@ public class TraceableScheduledExecutorServiceTest { this.traceableScheduledExecutorService.schedule(aCallable(), 1L, TimeUnit.DAYS); then(this.scheduledExecutorService).should(never()).schedule( - (Callable) BDDMockito.argThat(matcher(instanceOf(TraceCallable.class))), + BDDMockito.argThat( + matcher(Callable.class, instanceOf(TraceCallable.class))), anyLong(), any(TimeUnit.class)); } @@ -134,8 +140,9 @@ public class TraceableScheduledExecutorServiceTest { TimeUnit.DAYS); then(this.scheduledExecutorService).should(never()).scheduleAtFixedRate( - BDDMockito.argThat(matcher(instanceOf(TraceRunnable.class))), anyLong(), - anyLong(), any(TimeUnit.class)); + BDDMockito.argThat( + matcher(Runnable.class, instanceOf(TraceRunnable.class))), + anyLong(), anyLong(), any(TimeUnit.class)); } @Test @@ -146,15 +153,16 @@ public class TraceableScheduledExecutorServiceTest { TimeUnit.DAYS); then(this.scheduledExecutorService).should(never()).scheduleWithFixedDelay( - BDDMockito.argThat(matcher(instanceOf(TraceRunnable.class))), anyLong(), - anyLong(), any(TimeUnit.class)); + BDDMockito.argThat( + matcher(Runnable.class, instanceOf(TraceRunnable.class))), + anyLong(), anyLong(), any(TimeUnit.class)); } Predicate instanceOf(Class clazz) { return (argument) -> argument.getClass().isAssignableFrom(clazz); } - ArgumentMatcher matcher(Predicate predicate) { + ArgumentMatcher matcher(Class clazz, Predicate predicate) { return predicate::test; } diff --git a/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/grpc/stubs/HelloServiceOuterClass.java b/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/grpc/stubs/HelloServiceOuterClass.java index 5faddc0c6..3e6e6b798 100644 --- a/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/grpc/stubs/HelloServiceOuterClass.java +++ b/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/grpc/stubs/HelloServiceOuterClass.java @@ -21,12 +21,13 @@ public final class HelloServiceOuterClass { private HelloServiceOuterClass() { } - public static void registerAllExtensions() { + public static void registerAllExtensions( + com.google.protobuf.ExtensionRegistryLite registry) { } public static void registerAllExtensions( com.google.protobuf.ExtensionRegistry registry) { - registerAllExtensions(); + registerAllExtensions((com.google.protobuf.ExtensionRegistryLite) registry); } static final com.google.protobuf.Descriptors.Descriptor internal_static_sample_grpc_HelloRequest_descriptor; diff --git a/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/web/client/feign/issues/issue307/Issue307Tests.java b/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/web/client/feign/issues/issue307/Issue307Tests.java index 76f5c907b..e3741d521 100644 --- a/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/web/client/feign/issues/issue307/Issue307Tests.java +++ b/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/web/client/feign/issues/issue307/Issue307Tests.java @@ -112,7 +112,7 @@ class ParticipantsBean { return this.participantsClient.getParticipants(raceId); } - public List defaultParticipants() { + public List defaultParticipants(String raceId) { return new ArrayList<>(); } diff --git a/spring-cloud-sleuth-zipkin/src/main/java/org/springframework/cloud/sleuth/zipkin2/sender/ZipkinRestTemplateSenderConfiguration.java b/spring-cloud-sleuth-zipkin/src/main/java/org/springframework/cloud/sleuth/zipkin2/sender/ZipkinRestTemplateSenderConfiguration.java index b721f1e60..6c9619459 100644 --- a/spring-cloud-sleuth-zipkin/src/main/java/org/springframework/cloud/sleuth/zipkin2/sender/ZipkinRestTemplateSenderConfiguration.java +++ b/spring-cloud-sleuth-zipkin/src/main/java/org/springframework/cloud/sleuth/zipkin2/sender/ZipkinRestTemplateSenderConfiguration.java @@ -114,7 +114,7 @@ class ZipkinRestTemplateSenderConfiguration { ZipkinUrlExtractor zipkinUrlExtractor(final ZipkinLoadBalancer zipkinLoadBalancer) { return new ZipkinUrlExtractor() { @Override - public URI zipkinUrl() { + public URI zipkinUrl(ZipkinProperties zipkinProperties) { return zipkinLoadBalancer.instance(); } }; @@ -145,7 +145,7 @@ class ZipkinRestTemplateWrapper extends RestTemplate { protected T doExecute(URI originalUrl, HttpMethod method, RequestCallback requestCallback, ResponseExtractor responseExtractor) throws RestClientException { - URI uri = this.extractor.zipkinUrl(); + URI uri = this.extractor.zipkinUrl(this.zipkinProperties); URI newUri = resolvedZipkinUri(originalUrl, uri); return super.doExecute(newUri, method, requestCallback, responseExtractor); } @@ -175,7 +175,7 @@ class ZipkinRestTemplateWrapper extends RestTemplate { */ interface ZipkinUrlExtractor { - URI zipkinUrl(); + URI zipkinUrl(ZipkinProperties zipkinProperties); }