Introduce TaskDecorator variant for Context Propagation #31130
Labels
in: core
Issues in core modules (aop, beans, core, context, expression)
theme: observability
An issue related to observability and tracing
type: enhancement
A general enhancement
Milestone
As discussed in #30089 and #29977, Spring Framework does not intend to instrument
@Async
or@EventListener
methods for Observations. Creating dedicated observations would require:Also, many Spring applications can process a high number of application events. By default, those are designed to be processed quickly and synchronously within the publisher thread. Measuring processing time there will waste CPU cycles and yield very small measurements that are within the error margin.
On the other hand, there are cases where an existing observation is already active. For example, a web application receives a request and publishes an event as a result. If the dispatching of application events is done on a different Thread, the current context (i.e. ThreadLocals) is lost. This means that the observation trace is not propagated and that the logging context (the MDC information) is not present during execution.
Such use cases are covered by the Micrometer Context Propagation library. This issue is about offering an opt-in, flexible way of propagating context for
@Async
and@EventListener
annotated methods. Some applications might want to apply this globally, while others probably want to apply it selectively in order not to introduce unnecessary overhead in the application.We can introduce here a new
TaskDecorator
implementation that calls the Context Propagation library. If the application uses anExecutorService
directly, wrapping it with theio.micrometer.context.ContextExecutorService
is the best choice.The text was updated successfully, but these errors were encountered: