Closed mrodal-onlab closed 3 weeks ago
Can you share how you are populating the MDC and what you expect would propagate the MDC?
Im not populating the MDC, it is being populated by micrometer I believe. Heres a sample application: https://github.com/mrodal/issue-context-propagation
Its just a controller with the code above and the application starter with the Hooks.enableAutomaticContextPropagation();
Ok. I'm not sure what exactly you are trying to achieve, but you are creating a disconnected pipeline when you call .subscribe()
. Essentially, all that is present in the MDC is coming from Context
associated with the incoming request. The gist is - you return some Flux
/Mono
in your controllers to which the framework subscribes. A Subscriber
carries a Context
that represents an Observation
associated with that request processing. Micrometer-Tracing takes care of populating the MDC with trace-id/span-id metadata taken from the Observation
that is present in the Context
. Once you create another Flux
/Mono
which does not form a reactive chain with the existing Subscriber
then it contains an empty Context
that does not have that Observation
. This fire-and-forget pattern can lead to such issues. Consider asking a question on Gitter or StackOverflow how to best structure your code for the actual use case that you have and make sure you consult our reference documentation on this.
The example code is a simplification of the spring-statemachine library code. I'll check over there if they can find a workaround Thank you
Expected Behavior
Found the issue using spring-statemachine. Somewhere in the statemachine the logging context was getting lost. Debugging I found the part where this was happening, and could extract a small code sample that reproduces the error. The error happens when using
Hooks.enableAutomaticContextPropagation();
and it works as expected when not using it.Actual Behavior
Context is not being propagated when using
Hooks.enableAutomaticContextPropagation();
Steps to Reproduce
Your Environment
netty
, ...):spring boot 3.3.3
,micrometer-core 1.13.3
,micrometer-tracing 1.3.3
java -version
): java 17uname -a
): Windows 10