Reputation: 586
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?
Upvotes: 0
Views: 8093
Reputation: 11
The below solution worked for me.
App A using Spring boot 3.x to consume App B which uses Spring boot 2.7/x
App A uses RestClient to do a HTTP call to App B.
Spring boot 3.x doesn't have direct support of Sleuth but it can be achieved via Micrometer brave tracing.
Micrometer tracing default support format is w3c and Spring Sleuth support format is b3.
For a proper distributed tracing, the relevant properties to be added in both the applications (App A and App B)
In App A, Dependencies
application properties
management.tracing.sampling.probability=1.0
management.tracing.propagation.type=b3
management.tracing.brave.span-joining-supported=true
Ensure to create a bean like below
@Bean public RestClient restClient(RestClient.Builder builder){ return builder.build();}
The RestClient.Builder should be in the arg to make it work. Do not prefer RestClient.builder().build as it fails to add the tracing properties in the header during propagation. (For WebClient ensure to pass WebClient.Builder in the arg)
In App B, application properties to have
The above configurations works fine to propagate the tracing id from App A to App B.
This will not break, If you have App C which uses 2.7 to consume App B.
And, if App A gonna call App D which uses 3.x as well. The suggested to update the App A property management.tracing.propagation.type=b3,w3c (OR) update App D configuration as management.tracing.propagation.type=b3
Upvotes: 1
Reputation: 3819
you have to update the propagation.type
property in spring boot 3 project as well.
management.tracing.propagation.type=b3
and, make sure to add these dependencies.
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-tracing-bridge-brave</artifactId>
</dependency>
<dependency>
<groupId>io.zipkin.reporter2</groupId>
<artifactId>zipkin-reporter-brave</artifactId>
</dependency>
Upvotes: 3
Reputation: 586
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
Upvotes: 5