Pickup coroutineContext saved by CoWebFilter in coRouter #31793
Closed
Description
This was problem initially brought up here: micrometer-metrics/tracing#174 (comment) by @meberhard.
Problem: Currently the only place in Spring Framework that is picking up CoWebFilter.COROUTINE_CONTEXT_ATTRIBUTE
is this: https://github.com/spring-projects/spring-framework/blob/main/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/InvocableHandlerMethod.java#L296
but this code does not get executed for coRouter
handlers. This means that the handlers installed by coRouter
won't inherit the coroutineContext from CoWebFilter(s).
Known workarounds: you can add the look up into each instance of coRouter
DSL manually:
coRouter {
context { it.exchange().attributes[CoWebFilter.COROUTINE_CONTEXT_ATTRIBUTE] as CoroutineContext }
GET("/demo", demoHandler::demoCall)
}
To show case it, I have the following example:
- LoggingCoRouterV1 a very simple router with a GET endpoint and a few logging statements
- BaggageAddingFilter a filter (based on CoWebFilter) which is modifying coroutineContext