spring-cloud-sleuth
spring-cloud-sleuth copied to clipboard
W3C baggage extraction fails when traceparent header not present
Describe the bug
We need the baggage
header to be extracted whether there is a traceparent
header or not.
Sample I've written a branch here: https://github.com/jamesmoessis/spring-cloud-sleuth/tree/showcase-issue
The sample sleuth application can be run and called by the testing.http
file.
We are looking into possible solutions here since this is quite critical for us. We would appreciate some advice into how a solution might look for this. The problem is without a traceparent, there is no context to attach a baggage to. Is there a nice solution to this problem?
Why would the baggage be propagated if there's no tracing context in the first place?
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.
The w3c baggage header specification doesn't mention a tracing context specifically, but rather states that libraries should propagate the baggage
header downstream. In our case we want to propagate tenancy information, which is completely unrelated to tracing.
I don't actually know whether Sleuth would be the right place to implement this logic, given the aim of the library is to handle distributed tracing. At the same time it seems somewhat fit to put the logic into it given it handles header propagation concerns already.
I think this is related to https://github.com/spring-cloud/spring-cloud-sleuth/issues/2190 which is related to https://github.com/micrometer-metrics/tracing/pull/71/files . I will close #2208
@marcingrzejszczak Can I suggest going forward the W3C trace context propagators and W3C baggage propagator should be two separate implementations of Propagation
. They propagate independently of each other so there is no need to couple them together. This is indeed how OpenTelemetry implements it here and here, generally then tied together with a composite propagator.
From the w3c spec, my understanding is Baggage is independent with Trace Context, Trace Context contains traceparent and tracestate, which means using tracestate if user wants to propagate something when traceparent(trace id, span id, trace flags) must present, using Baggage if user wants to propagate something regardless tracing is enabled. So, correct me if I am wrong, the implementation should support propagate Baggage propagation even traceparent not present.
@wangzlei in newer implementations (Micrometer Tracing + Otel) this works now. Sleuth is deprecated.
That's not how it works in Sleuth. It works like this only with Tracing and OTel as @jamesmoessis mentioned