Class TracingChannelInterceptor
java.lang.Object
org.springframework.cloud.sleuth.instrument.messaging.TracingChannelInterceptor
- All Implemented Interfaces:
org.springframework.beans.factory.Aware,org.springframework.context.ApplicationContextAware,org.springframework.messaging.support.ChannelInterceptor,org.springframework.messaging.support.ExecutorChannelInterceptor
public final class TracingChannelInterceptor
extends Object
implements org.springframework.messaging.support.ExecutorChannelInterceptor, org.springframework.context.ApplicationContextAware
This starts and propagates
Span.Kind.PRODUCER span for each message sent (via
native headers. It also extracts or creates a Span.Kind.CONSUMER span for each
message received. This span is injected onto each message so it becomes the parent when
a handler later calls MessageHandler.handleMessage(Message).- Since:
- 3.0.0
- Author:
- Marcin Grzejszczak, Artem Bilan
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringName of the class in Spring Cloud Stream that is a direct channel. -
Constructor Summary
ConstructorsConstructorDescriptionTracingChannelInterceptor(Tracer tracer, Propagator propagator, Propagator.Setter<org.springframework.messaging.support.MessageHeaderAccessor> setter, Propagator.Getter<org.springframework.messaging.support.MessageHeaderAccessor> getter, Function<String, String> remoteServiceNameMapper, MessageSpanCustomizer messageSpanCustomizer) -
Method Summary
Modifier and TypeMethodDescriptionvoidafterMessageHandled(org.springframework.messaging.Message<?> message, org.springframework.messaging.MessageChannel channel, org.springframework.messaging.MessageHandler handler, Exception ex) voidafterReceiveCompletion(org.springframework.messaging.Message<?> message, org.springframework.messaging.MessageChannel channel, Exception ex) voidafterSendCompletion(org.springframework.messaging.Message<?> message, org.springframework.messaging.MessageChannel channel, boolean sent, Exception ex) org.springframework.messaging.Message<?>beforeHandle(org.springframework.messaging.Message<?> message, org.springframework.messaging.MessageChannel channel, org.springframework.messaging.MessageHandler handler) This starts a consumer span as a child of the incoming message or the current trace context.org.springframework.messaging.Message<?>postReceive(org.springframework.messaging.Message<?> message, org.springframework.messaging.MessageChannel channel) This starts a consumer span as a child of the incoming message or the current trace context, placing it in scope until the receive completes.org.springframework.messaging.Message<?>preSend(org.springframework.messaging.Message<?> message, org.springframework.messaging.MessageChannel channel) Starts and propagatesSpan.Kind.PRODUCERspan for each message sent.voidsetApplicationContext(org.springframework.context.ApplicationContext applicationContext) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.messaging.support.ChannelInterceptor
postSend, preReceive
-
Field Details
-
STREAM_DIRECT_CHANNEL
Name of the class in Spring Cloud Stream that is a direct channel.- See Also:
-
-
Constructor Details
-
TracingChannelInterceptor
public TracingChannelInterceptor(Tracer tracer, Propagator propagator, Propagator.Setter<org.springframework.messaging.support.MessageHeaderAccessor> setter, Propagator.Getter<org.springframework.messaging.support.MessageHeaderAccessor> getter, Function<String, String> remoteServiceNameMapper, MessageSpanCustomizer messageSpanCustomizer)
-
-
Method Details
-
setApplicationContext
public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext) throws org.springframework.beans.BeansException - Specified by:
setApplicationContextin interfaceorg.springframework.context.ApplicationContextAware- Throws:
org.springframework.beans.BeansException
-
preSend
public org.springframework.messaging.Message<?> preSend(org.springframework.messaging.Message<?> message, org.springframework.messaging.MessageChannel channel) Starts and propagatesSpan.Kind.PRODUCERspan for each message sent.- Specified by:
preSendin interfaceorg.springframework.messaging.support.ChannelInterceptor
-
afterSendCompletion
public void afterSendCompletion(org.springframework.messaging.Message<?> message, org.springframework.messaging.MessageChannel channel, boolean sent, Exception ex) - Specified by:
afterSendCompletionin interfaceorg.springframework.messaging.support.ChannelInterceptor
-
postReceive
public org.springframework.messaging.Message<?> postReceive(org.springframework.messaging.Message<?> message, org.springframework.messaging.MessageChannel channel) This starts a consumer span as a child of the incoming message or the current trace context, placing it in scope until the receive completes.- Specified by:
postReceivein interfaceorg.springframework.messaging.support.ChannelInterceptor
-
afterReceiveCompletion
public void afterReceiveCompletion(org.springframework.messaging.Message<?> message, org.springframework.messaging.MessageChannel channel, Exception ex) - Specified by:
afterReceiveCompletionin interfaceorg.springframework.messaging.support.ChannelInterceptor
-
beforeHandle
public org.springframework.messaging.Message<?> beforeHandle(org.springframework.messaging.Message<?> message, org.springframework.messaging.MessageChannel channel, org.springframework.messaging.MessageHandler handler) This starts a consumer span as a child of the incoming message or the current trace context. It then creates a span for the handler, placing it in scope.- Specified by:
beforeHandlein interfaceorg.springframework.messaging.support.ExecutorChannelInterceptor
-
afterMessageHandled
public void afterMessageHandled(org.springframework.messaging.Message<?> message, org.springframework.messaging.MessageChannel channel, org.springframework.messaging.MessageHandler handler, Exception ex) - Specified by:
afterMessageHandledin interfaceorg.springframework.messaging.support.ExecutorChannelInterceptor
-