spring-projects / spring-statemachine

Spring Statemachine is a framework for application developers to use state machine concepts with Spring.
1.57k stars 616 forks source link

Tracing context lost in actions/guards #1162

Open mrodal opened 2 months ago

mrodal commented 2 months ago

The tracing context is being lost when executing triggers in ReactiveStateMachineExecutor I've uploaded a simple example project with this configuration: https://github.com/mrodal/issue-context-propagation/blob/master/src/main/java/issues/context_propagation/Controller.java

As you can see the tracing is missing when inside the action:

image

Debugging I managed to find the part where it is getting lost, in this flatMap: https://github.com/spring-projects/spring-statemachine/blob/4dcf6dc53102257eea74d79818166f53b1068a11/spring-statemachine-core/src/main/java/org/springframework/statemachine/support/ReactiveStateMachineExecutor.java#L119

The example project has a controller with 2 endpoints

The issue only happens when using Hooks.enableAutomaticContextPropagation() which we need to keep tracing in other parts of the code. I've reported the issue to the reactor team and you can see their response here: https://github.com/reactor/reactor-core/issues/3887

Related issues: https://github.com/micrometer-metrics/tracing/issues/359 https://github.com/reactor/reactor-core/issues/3887