Search code examples
springspring-cloud-sleuth

Spring Sleuth does not populate traceid and spanid to RabbitHandler


We want to use spring sleuth together with spring-amqp (rabbitmq). So we send a message on the publisher site via

amqpTemplate.convertAndSend("exchange", "key", myEvent)

and expect to have traceid and spanid send along with the rabbit message and populated on the receiver/listener site, so it will be logged on the listener site too.

@RabbitHandler
public void on(MyEvent event) {
  LOGGER.warn("got a message...");
  ...
}

According to this article I would expect this to work out of the box.

If I check the RabbitMQ messages directly (via trace), then I can see that the information is not available in the message, therefore its most probably the sender site having an issue...

One thing coming to my mind is, that we have configured a Jackson2JsonMessageConverter to allow json payloads:

@Bean
public Jackson2JsonMessageConverter jacksonConverter(ObjectMapper objectMapper) {
    return new Jackson2JsonMessageConverter(objectMapper);
}

btw. the log4j pattern is configured with the %X and prints the info if available:

<PatternLayout pattern="%d{HH:mm:ss.SSS} %X [%thread] %-5level %logger{36} - %msg%n" />

what did I miss?


Solution

  • You missed the last piece of this sentence

    requests over messaging technologies like Apache Kafka or RabbitMQ (or any other Spring Cloud Stream binder

    Sleuth doesn't work with RabbitHandler. In terms of messaging it works only with Spring Integration and Spring Cloud Stream.