spring-bootspring-cloud-sleuthspring-micrometermicrometer-tracing

Lost traceId between Spring Boot services 2.x and 3.0 version


I have multiple services running with Spring Boot 2.7 and I am starting to create new services with Spring Boot 3.0. And I have the same problem as in this other question but neither the accepted solution nor the attached migration guide has worked. The behaviour during the requests is the next:

Service (2.7 - TraceId-X) -> Service (3.0 - TraceId-X) => OK
Service (3.0 - TraceId-X) -> Service (3.0 - TraceId-Y) => TraceId-X lost
Service (3.0 - TraceId-X) -> Service (2.7 - TraceId-Y) => TraceId-X lost

In short, when the request starts or goes through a service with version 3.0 the traceId is lost (it has been replaced by a new one).

application.yml (2.7):

spring.sleuth.propagation.type: w3c,b3
spring.sleuth.traceId128: true
spring.sleuth.supportsJoin: false

application.yml (3.0):

logging.pattern.level: "%5p [${spring.application.name:},%X{traceId:-},%X{spanId:-}]"

The versions of the main dependencies are: Services with 2.7 version:

Services with 3.0 version:

I can understand that there are integration problems between services of different versions, but there are also integration problems between Spring 3.0 services. What could I be missing in the configuration?


Solution

  • I do not like to answer my own question but I found the solution and maybe it will help someone in the future.

    I did not realise that in most guides and tutorials on the internet they use RestTemplate to communicate between services. In my case, I am using Feign clients. And they need a specific library for micrometer.

    <dependency>
      <groupId>io.github.openfeign</groupId>
      <artifactId>feign-micrometer</artifactId>
    </dependency>
    

    Reference: https://docs.spring.io/spring-cloud-openfeign/docs/current/reference/html/#micrometer-support