How to set coroutine context from spring webflux WebFilter? Is it possible? I know I can use reactor context, but I'm not able to set coroutine context.
MORE DETAILS:
I want to use MDCContext to propagate MDC to slf4j. For example, I would like to get MDC from HTTP headers and then I want these values to be automatically propagated to any log I write.
Currently, I can:
- I set reactor context in WebFilter
- in every controller I get values from reactor context and put them inside MDCContext (coroutine)
As you see, this is not very convenient as I have to add extra code in the controllers.
Is there a way to automatically transform Reactor context to coroutine context? I know I can do vice versa with ContextInjector and ServiceLoader (see https://github.com/Kotlin/kotlinx.coroutines/issues/284#issuecomment-516270570), but it seems there is no such mechanism for reverse conversion.
Unfortunately, it is not possible now. There is an open issue in spring framework to fix this that you can upvote -> https://github.com/spring-projects/spring-framework/issues/26977