Search code examples
activemq-classicspring-cloud-sleuth

Sleuth traceId and spanId not logged in activeMQ Listener


I'm trying to configure a microservice with Sleuth and ActiveMQ. When starting a request I can properly see appName, traceId and spanId in logs of producer, but after dequeuing the message in listener I find only appName, without traceId and spanId. How can I get this fields filled?

Right now I'm working with spring.sleuth.messaging.jms.enabled=false to avoid this exception at startup:

  • Bean named 'connectionFactory' is expected to be of type 'org.apache.activemq.ActiveMQConnectionFactory' but was actually of type 'org.springframework.cloud.sleuth.instrument.messaging.LazyConnectionFactory'

My dependencies:

  • org.springframework.boot.spring-boot-starter-activemq 2.5.1

  • org.springframework.cloud.spring-cloud-sleuth 3.0.3

Thank you all!


Solution

  • My understanding is that the properties you're looking for are set on the JMS message when the message is sent and then retrieved from the message when it is consumed. Since you're setting spring.sleuth.messaging.jms.enabled=false you're disabling this functionality. See the documentation which states:

    We instrument the JmsTemplate so that tracing headers get injected into the message. We also support @JmsListener annotated methods on the consumer side.

    To block this feature, set spring.sleuth.messaging.jms.enabled to false.

    You'll need to find an alternate solution for the connection factory problem if you want to use Sleuth with Spring JMS. If you're injecting org.apache.activemq.ActiveMQConnectionFactory somewhere then you should almost certainly be using javax.jms.ConnectionFactory instead. Using the concrete type is bad for portability and use-cases like this where wrapper implementations are used dynamically.