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 8f45fe7f9..05e79bd76 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 @@ -81,6 +81,7 @@ public final class TracingChannelInterceptor extends ChannelInterceptorAdapter final ThreadLocalSpan threadLocalSpan; final TraceContext.Injector injector; final TraceContext.Extractor extractor; + final boolean integrationObjectSupportPresent; TracingChannelInterceptor(Tracing tracing) { this.tracing = tracing; @@ -90,6 +91,9 @@ public final class TracingChannelInterceptor extends ChannelInterceptorAdapter .injector(MessageHeaderPropagation.INSTANCE); this.extractor = tracing.propagation() .extractor(MessageHeaderPropagation.INSTANCE); + this.integrationObjectSupportPresent = ClassUtils.isPresent( + "org.springframework.integration.context.IntegrationObjectSupport", + null); } /** @@ -260,18 +264,16 @@ public final class TracingChannelInterceptor extends ChannelInterceptorAdapter /** * When an upstream context was not present, lookup keys are unlikely added */ - static void addTags(Message message, SpanCustomizer result, MessageChannel channel) { + void addTags(Message message, SpanCustomizer result, MessageChannel channel) { // TODO topic etc if (channel != null) { result.tag("channel", messageChannelName(channel)); } } - private static String channelName(MessageChannel channel) { + private String channelName(MessageChannel channel) { String name = null; - if (ClassUtils.isPresent( - "org.springframework.integration.context.IntegrationObjectSupport", - null)) { + if (this.integrationObjectSupportPresent) { if (channel instanceof IntegrationObjectSupport) { name = ((IntegrationObjectSupport) channel).getComponentName(); } @@ -285,7 +287,7 @@ public final class TracingChannelInterceptor extends ChannelInterceptorAdapter return name; } - private static String messageChannelName(MessageChannel channel) { + private String messageChannelName(MessageChannel channel) { return SpanNameUtil.shorten(channelName(channel)); }