Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Out of the box MDC support in WebClient #24416

Closed
ttddyy opened this issue Jan 22, 2020 · 3 comments
Closed

Out of the box MDC support in WebClient #24416

ttddyy opened this issue Jan 22, 2020 · 3 comments
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: declined A suggestion or change that we don't feel we should currently apply

Comments

@ttddyy
Copy link
Contributor

ttddyy commented Jan 22, 2020

When using WebClient in servlet environment, MDC is one of the pain point that requires boilerplate code.
Since RestTemplate is in maintenance mode, more and more apps would choose to use WebClient.
It would be very helpful that spring provides out of the box support for MDC for the use of WebClient. Then, it would be a smooth ride migrating RestTemplate to WebClient.

Since spring already detects underlying logging framework, it could be implemented agnostic to the actual logging framework.

What needs to be implemented:

  • Pass MDC values from main thread to reactor thread
    In servlet environment, it is required to propagate MDC context values from servlet thread to reactor thread.
    To implement, ExchangeFilterFunction or some sort of hook which should apply as the first action of response operators.

  • Pass around MDC values to subscriber context within reactor schedulers/operators
    My suggestion to reactor-addons. Add-on to support MDC reactor/reactor-addons#219

If such boilerplate code is provided from spring, then, spring-boot may auto-configure the MDC support.

Relates to reactor/reactor-core#1985

@northernbird
Copy link

Hello, I also need this feature. Could someone provide any updated info?

@Anonymous-Coward
Copy link

The problem exists for filters in spring cloud gateway too, not just for WebClient. I looked at the logback code on github. I suppose the problem can be solved at the very root of it if spring webflux injects its own MDC adapter implementation - that one can bind to the exchange, rather than the default which binds to the thread.

@rstoyanchev rstoyanchev added the in: web Issues in web modules (web, webmvc, webflux, websocket) label Nov 8, 2021
@bclozel
Copy link
Member

bclozel commented Feb 18, 2022

Closing as this is not specific to WebClient, but rather a general context propagation issue with ThreadLocals. This should be addressed in Reactor directly. Work has been done in Spring GraphQL in that direction.

@bclozel bclozel closed this as completed Feb 18, 2022
@bclozel bclozel added status: declined A suggestion or change that we don't feel we should currently apply and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Feb 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: declined A suggestion or change that we don't feel we should currently apply
Projects
None yet
Development

No branches or pull requests

6 participants