Skip to content

Out of the box MDC support in WebClient #24416

@ttddyy

Description

@ttddyy

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: webIssues in web modules (web, webmvc, webflux, websocket)status: declinedA suggestion or change that we don't feel we should currently apply

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions