Class 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

      Fields 
      Modifier and Type Field Description
      static String STREAM_DIRECT_CHANNEL
      Name of the class in Spring Cloud Stream that is a direct channel.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void afterMessageHandled​(org.springframework.messaging.Message<?> message, org.springframework.messaging.MessageChannel channel, org.springframework.messaging.MessageHandler handler, Exception ex)  
      void afterReceiveCompletion​(org.springframework.messaging.Message<?> message, org.springframework.messaging.MessageChannel channel, Exception ex)  
      void afterSendCompletion​(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 propagates Span.Kind.PRODUCER span for each message sent.
      void setApplicationContext​(org.springframework.context.ApplicationContext applicationContext)  
      • Methods inherited from interface org.springframework.messaging.support.ChannelInterceptor

        postSend, preReceive
    • Field Detail

      • STREAM_DIRECT_CHANNEL

        public static final String STREAM_DIRECT_CHANNEL
        Name of the class in Spring Cloud Stream that is a direct channel.
        See Also:
        Constant Field Values
    • Method Detail

      • setApplicationContext

        public void setApplicationContext​(org.springframework.context.ApplicationContext applicationContext)
                                   throws org.springframework.beans.BeansException
        Specified by:
        setApplicationContext in interface org.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 propagates Span.Kind.PRODUCER span for each message sent.
        Specified by:
        preSend in interface org.springframework.messaging.support.ChannelInterceptor
      • afterSendCompletion

        public void afterSendCompletion​(org.springframework.messaging.Message<?> message,
                                        org.springframework.messaging.MessageChannel channel,
                                        boolean sent,
                                        Exception ex)
        Specified by:
        afterSendCompletion in interface org.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:
        postReceive in interface org.springframework.messaging.support.ChannelInterceptor
      • afterReceiveCompletion

        public void afterReceiveCompletion​(org.springframework.messaging.Message<?> message,
                                           org.springframework.messaging.MessageChannel channel,
                                           Exception ex)
        Specified by:
        afterReceiveCompletion in interface org.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:
        beforeHandle in interface org.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:
        afterMessageHandled in interface org.springframework.messaging.support.ExecutorChannelInterceptor