This was problem initially brought up here: https://github.com/micrometer-metrics/tracing/issues/174#issuecomment-1835724109 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