diff --git a/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/messaging/TraceSpringIntegrationAutoConfiguration.java b/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/messaging/TraceSpringIntegrationAutoConfiguration.java index d9eb1b008..b7d1271b5 100644 --- a/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/messaging/TraceSpringIntegrationAutoConfiguration.java +++ b/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/messaging/TraceSpringIntegrationAutoConfiguration.java @@ -54,7 +54,7 @@ import org.springframework.messaging.support.MessageBuilder; public class TraceSpringIntegrationAutoConfiguration { @Bean - @GlobalChannelInterceptor(patterns = "${spring.sleuth.integration.patterns:*}") + @GlobalChannelInterceptor public TraceChannelInterceptor traceChannelInterceptor(Tracer tracer, TraceKeys traceKeys, Random random, SpanExtractor> spanExtractor, SpanInjector> spanInjector) { diff --git a/spring-cloud-sleuth-core/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/spring-cloud-sleuth-core/src/main/resources/META-INF/additional-spring-configuration-metadata.json deleted file mode 100644 index 3dfc54046..000000000 --- a/spring-cloud-sleuth-core/src/main/resources/META-INF/additional-spring-configuration-metadata.json +++ /dev/null @@ -1,14 +0,0 @@ -{"properties": [ - { - "name": "spring.sleuth.integration.patterns", - "type": "java.lang.String[]", - "description": "An array of simple patterns against which channel names will be matched. Default is * (all channels). See org.springframework.util.PatternMatchUtils.simpleMatch(String, String).", - "defaultValue": "*" - }, - { - "name": "spring.sleuth.integration.enabled", - "type": "java.lang.Boolean", - "description": "Enable Spring Integration sleuth instrumentation.", - "defaultValue": true - } -]} \ No newline at end of file diff --git a/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/messaging/TraceChannelInterceptorTests.java b/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/messaging/TraceChannelInterceptorTests.java index 2a8bb6589..6702bfcbb 100644 --- a/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/messaging/TraceChannelInterceptorTests.java +++ b/spring-cloud-sleuth-core/src/test/java/org/springframework/cloud/sleuth/instrument/messaging/TraceChannelInterceptorTests.java @@ -16,10 +16,6 @@ package org.springframework.cloud.sleuth.instrument.messaging; -import static org.assertj.core.api.BDDAssertions.then; -import static org.junit.Assert.assertNotNull; -import static org.springframework.cloud.sleuth.assertions.SleuthAssertions.then; - import java.util.HashMap; import java.util.Map; @@ -30,8 +26,8 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.test.IntegrationTest; +import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.cloud.sleuth.Sampler; import org.springframework.cloud.sleuth.Span; import org.springframework.cloud.sleuth.Tracer; @@ -49,25 +45,23 @@ import org.springframework.messaging.Message; import org.springframework.messaging.MessageHandler; import org.springframework.messaging.MessagingException; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import static org.junit.Assert.assertNotNull; +import static org.springframework.cloud.sleuth.assertions.SleuthAssertions.then; + /** * @author Dave Syer */ @RunWith(SpringJUnit4ClassRunner.class) -@SpringBootTest(classes = App.class, webEnvironment = WebEnvironment.NONE) +@SpringApplicationConfiguration(classes = App.class) +@IntegrationTest @DirtiesContext -@TestPropertySource(properties = "spring.sleuth.integration.patterns=traced*") public class TraceChannelInterceptorTests implements MessageHandler { @Autowired - @Qualifier("tracedChannel") - private DirectChannel tracedChannel; - - @Autowired - @Qualifier("ignoredChannel") - private DirectChannel ignoredChannel; + @Qualifier("channel") + private DirectChannel channel; @Autowired private Tracer tracer; @@ -93,22 +87,20 @@ public class TraceChannelInterceptorTests implements MessageHandler { @Before public void init() { - this.tracedChannel.subscribe(this); - this.ignoredChannel.subscribe(this); + this.channel.subscribe(this); this.accumulator.getSpans().clear(); } @After public void close() { TestSpanContextHolder.removeCurrentSpan(); - this.tracedChannel.unsubscribe(this); - this.ignoredChannel.unsubscribe(this); + this.channel.unsubscribe(this); this.accumulator.getSpans().clear(); } @Test public void nonExportableSpanCreation() { - this.tracedChannel.send(MessageBuilder.withPayload("hi") + this.channel.send(MessageBuilder.withPayload("hi") .setHeader(Span.SAMPLED_NAME, Span.SPAN_NOT_SAMPLED).build()); assertNotNull("message was null", this.message); @@ -120,7 +112,7 @@ public class TraceChannelInterceptorTests implements MessageHandler { @Test public void parentSpanIncluded() { - this.tracedChannel.send(MessageBuilder.withPayload("hi") + this.channel.send(MessageBuilder.withPayload("hi") .setHeader(Span.TRACE_ID_NAME, Span.idToHex(10L)) .setHeader(Span.SPAN_ID_NAME, Span.idToHex(20L)).build()); then(this.message).isNotNull(); @@ -137,7 +129,7 @@ public class TraceChannelInterceptorTests implements MessageHandler { // #332 @Test public void shouldSendNewAndOldHeadersWhenNewHeadersWerePassed() { - this.tracedChannel.send(MessageBuilder.withPayload("hi") + this.channel.send(MessageBuilder.withPayload("hi") .setHeader(TraceMessageHeaders.TRACE_ID_NAME, Span.idToHex(10L)) .setHeader(TraceMessageHeaders.SPAN_ID_NAME, Span.idToHex(20L)).build()); then(this.message).isNotNull(); @@ -149,8 +141,7 @@ public class TraceChannelInterceptorTests implements MessageHandler { } private String thenNewSpanIdEqualsOldSpanId() { - String newSpanId = this.message.getHeaders().get(TraceMessageHeaders.SPAN_ID_NAME, - String.class); + String newSpanId = this.message.getHeaders().get(TraceMessageHeaders.SPAN_ID_NAME, String.class); then(newSpanId).isNotNull(); String oldSpanId = this.message.getHeaders().get(Span.SPAN_ID_NAME, String.class); then(oldSpanId).isEqualTo(newSpanId); @@ -160,7 +151,7 @@ public class TraceChannelInterceptorTests implements MessageHandler { // #332 @Test public void shouldSendNewAndOldHeadersWhenOldHeadersWerePassed() { - this.tracedChannel.send(MessageBuilder.withPayload("hi") + this.channel.send(MessageBuilder.withPayload("hi") .setHeader(Span.TRACE_ID_NAME, Span.idToHex(10L)) .setHeader(Span.SPAN_ID_NAME, Span.idToHex(20L)).build()); then(this.message).isNotNull(); @@ -172,8 +163,8 @@ public class TraceChannelInterceptorTests implements MessageHandler { } private void thenNewTraceIdEqualsOldTraceId() { - long traceId = Span.hexToId(this.message.getHeaders() - .get(TraceMessageHeaders.TRACE_ID_NAME, String.class)); + long traceId = Span + .hexToId(this.message.getHeaders().get(TraceMessageHeaders.TRACE_ID_NAME, String.class)); then(traceId).isEqualTo(10L); long oldTraceId = Span .hexToId(this.message.getHeaders().get(Span.TRACE_ID_NAME, String.class)); @@ -182,7 +173,7 @@ public class TraceChannelInterceptorTests implements MessageHandler { @Test public void spanCreation() { - this.tracedChannel.send(MessageBuilder.withPayload("hi").build()); + this.channel.send(MessageBuilder.withPayload("hi").build()); then(this.message).isNotNull(); String spanId = this.message.getHeaders().get(Span.SPAN_ID_NAME, String.class); @@ -195,25 +186,22 @@ public class TraceChannelInterceptorTests implements MessageHandler { @Test public void shouldLogClientReceivedClientSentEventWhenTheMessageIsSentAndReceived() { - this.tracedChannel.send(MessageBuilder.withPayload("hi").build()); + this.channel.send(MessageBuilder.withPayload("hi").build()); - then(this.span.logs()).extracting("event").contains(Span.CLIENT_SEND, - Span.CLIENT_RECV); + then(this.span.logs()).extracting("event").contains(Span.CLIENT_SEND, Span.CLIENT_RECV); } @Test public void shouldLogServerReceivedServerSentEventWhenTheMessageIsPropagatedToTheNextListener() { - this.tracedChannel.send(MessageBuilder.withPayload("hi") - .setHeader("X-Message-Sent", true).build()); + this.channel.send(MessageBuilder.withPayload("hi").setHeader("X-Message-Sent", true).build()); - then(this.span.logs()).extracting("event").contains(Span.SERVER_RECV, - Span.SERVER_SEND); + then(this.span.logs()).extracting("event").contains(Span.SERVER_RECV, Span.SERVER_SEND); } @Test public void headerCreation() { Span span = this.tracer.createSpan("http:testSendMessage", new AlwaysSampler()); - this.tracedChannel.send(MessageBuilder.withPayload("hi").build()); + this.channel.send(MessageBuilder.withPayload("hi").build()); this.tracer.close(span); then(this.message).isNotNull(); @@ -249,33 +237,15 @@ public class TraceChannelInterceptorTests implements MessageHandler { errorHeaders.put("THROW_EXCEPTION", "TRUE"); try { - this.messagingTemplate.send( - MessageBuilder.withPayload("hi").copyHeaders(errorHeaders).build()); + this.messagingTemplate.send(MessageBuilder.withPayload("hi").copyHeaders(errorHeaders).build()); SleuthAssertions.fail("Exception should occur"); - } - catch (RuntimeException e) { - } + } catch (RuntimeException e) {} then(this.message).isNotNull(); this.tracer.close(span); then(TestSpanContextHolder.getCurrentSpan()).isNull(); } - @Test - public void shouldNotTraceIgnoredChannel() { - this.ignoredChannel.send(MessageBuilder.withPayload("hi").build()); - then(this.message).isNotNull(); - - String spanId = this.message.getHeaders().get(Span.SPAN_ID_NAME, String.class); - then(spanId).isNull(); - - String traceId = this.message.getHeaders().get(Span.TRACE_ID_NAME, String.class); - then(traceId).isNull(); - - then(accumulator.getSpans()).isEmpty(); - then(TestSpanContextHolder.getCurrentSpan()).isNull(); - } - @Configuration @EnableAutoConfiguration static class App { @@ -286,18 +256,13 @@ public class TraceChannelInterceptorTests implements MessageHandler { } @Bean - public DirectChannel tracedChannel() { - return new DirectChannel(); - } - - @Bean - public DirectChannel ignoredChannel() { + public DirectChannel channel() { return new DirectChannel(); } @Bean public MessagingTemplate messagingTemplate() { - return new MessagingTemplate(tracedChannel()); + return new MessagingTemplate(channel()); } @Bean