spring-cloud / spring-cloud-sleuth

Distributed tracing for spring cloud
https://spring.io/projects/spring-cloud-sleuth
Apache License 2.0
1.78k stars 782 forks source link

Baggage propagation stop working after switching from B3 to either W3C or AWS #2345

Closed junhuangli closed 5 months ago

junhuangli commented 5 months ago

Describe the bug Please provide details of the problem, including the version of Spring Cloud that you are using.

According to this doc- https://docs.spring.io/spring-cloud-sleuth/docs/current/reference/html/project-features.html Our application is using baggage propagation to persist some tenant context between our micro-services. We are currently using B3 as the propagation.type and the baggage persistence is working fine. But after setting spring.sleuth.propagation.type=AWS, the baggage propagation stopped working and I found all our tenant context is disappeared from the request header.

Diving into the code a bit and I found the difference here - https://github.com/spring-cloud/spring-cloud-sleuth/blob/3.1.x/spring-cloud-sleuth-autoconfigure/src/main/java/org/springframework/cloud/sleuth/autoconfig/brave/BraveBaggageConfiguration.java#L169

If the spring.sleuth.propagation.type=B3, it will use the BaggagePropagation if not it is going to default to CompositePropagationFactory which doesn't write the baggage info to the header. Is this expected?

Sample If possible, please provide a test case or a minimal Maven sample written in Java that reproduces the problem. This makes it much easier for us to diagnose the problem and to verify that we have fixed it.

junhuangli commented 5 months ago

Found more info below(We are using Sleuth 3.1.4)

When spring.sleuth.propagation.type=B3, the Propagation.Factory is a BaggagePropagation object which takes care of both Tracing propagation and baggage propagation in https://github.com/openzipkin/brave/blob/master/brave/src/main/java/brave/baggage/BaggagePropagation.java#L306-L326

When spring.sleuth.propagation.type=AWS, the Propagation.Factory is a BaggageFactoryWrapper object which only does Tracing propagation.

Outgoing request header with "B3": 'x-b3-traceid', '****' 'x-b3-spanid', '***' 'x-b3-parentspanid', '***' 'x-b3-sampled', '0' 'mycontent.app', '***'

Outgoing request header with "AWS"("mycontent.app" is gone): 'x-amzn-trace-id', 'Root=1-***-***;Parent=***;Sampled=0'

marcingrzejszczak commented 5 months ago

Sleuth is a feature complete project that is out of OSS support. Please migrate to Micrometer Tracing