Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set coroutine context from spring webflux WebFilter

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.

like image 975
Eugene Nacu Avatar asked Apr 21 '26 15:04

Eugene Nacu


1 Answers

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

like image 147
walrus03 Avatar answered Apr 24 '26 04:04

walrus03



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!