New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Manually created baggage fields do not propagate across threads using ObservationAwareSpanThreadLocalAccessor #412
Comments
From playing with the library I noticed that:
All of this comes down to a subtle difference in what is available by default in each context. Tracing ids take the lack of an observation in context as a sign to recreate themselves, while custom baggages can't possibly be re-set as code creating them is not apart of the same library flow. If you by chance wrap the submit part in the observe scoped lambda do you still see them not propagating? |
Yes, using ReceiverContext<Map<String, String>> context = new ReceiverContext<>(Map::get);
context.setCarrier(Map.of("tenant", "tenant"));
Observation.createNotStarted("test", () -> context, observationRegistry).observe(() -> {
executor.submit(() -> {
String tenant = tracer.getBaggage("tenant").get();
// tenant should not be null
System.out.println(tenant);
});
}); Because But in this way, we don't even need a So, i still think |
In Brave, baggage is tightly associated with the TraceContext. When Baggage is put in scope, the value gets attached to TraceContext (TC). In version 1.1 we've introduced scoping also for Brave, which means that the moment you close the scope we will return to the previously created baggage version. Let us now imagine a situation where we open a scope for a span, within it we create a scope for baggage within which we are passing work to a separate thread (Span Scope -> Baggage Scope -> separate thread). Without this change when the baggage scope on outer part is closed, the TC will have the baggage value reverted to the previous value. That will impact the same TC that is passed to the separate thread. That means the value of the baggage will be reverted for the same TC which is in the main and the separate thread. This is why it can be surprising that even though in the main thread there was baggage, it was not propagated to the other thread (in reality the main thread altered a shared resource between main and separate threads). With this change, when OASTLA is getting the current span (in fact we're taking a snapshot of the span and baggage situation at this point in time) we are dumping also the corresponding baggage. That means that when the scope in the main thread gets closed, thus e.g. the values get reverted the TC in the second thread will not be affected. That's because when Context Propagation recreates the span scope, we will also recreate all the baggage scopes. Once the Context Propagation finishes its jobs we will close all the baggage scopes and lastly the span scope too. Fixed issues with SimpleTracer and its support for baggage. Also moved the OASTLA tests to integration tests module where we are using the same test logic with 3 different tracers, SimpleTracer, BraveTracer and OtelTracer fixes gh-412
A sample is like this, the value of baggage field 'tenant' is expected to propagated correctly. But it's
null
now.The sample can be found here https://github.com/wapkch/micrometer-tracing-demo/tree/master
The text was updated successfully, but these errors were encountered: