I used this solution https://github.com/archie-swif/webflux-mdc, the values can be obtained in the same stream, but not in different streams, this affects the logging id. How to solve?

eg: Setting parameters using webfilter

@Component
public class MdcWebFilter implements WebFilter {
    @Override
    public Mono<Void> filter(ServerWebExchange serverWebExchange, WebFilterChain webFilterChain) {
        return webFilterChain.filter(serverWebExchange).subscriberContext(ctx -> ctx.put("traceId", 123));
    }
}

@RestController
public class TestController {

    private final static Scheduler SETTLEMENT_SCHEDULER = Schedulers.newParallel("settlement-scheduler", 30);

    @GetMapping("/test")
    public Flux<Integer> test() {

        //123
        System.out.println(Thread.currentThread().getId() + ":" + MDC.get("traceId"));

        Mono.just(1).map(s -> {
            thread1();
            return 1;
        }).subscribeOn(SETTLEMENT_SCHEDULER).subscribe();

        return Flux.just(1).map(s -> {
            thread2();
            return 1;
        }).subscribeOn(SETTLEMENT_SCHEDULER);
    }

    private void thread1() {
        //null
        System.out.println(Thread.currentThread().getId() + ":" + MDC.get("traceId"));
    }

    private void thread2() {
        //123
        System.out.println(Thread.currentThread().getId() + ":" + MDC.get("traceId"));
    }

Comment From: rstoyanchev

Thanks for getting in touch, but it feels like this is a question that would be better suited to Stack Overflow. As mentioned in the guidelines for contributing, we prefer to use the issue tracker only for bugs and enhancements. Feel free to update this issue with a link to the re-posted question (so that other people can find it) or add some more details if you feel this is a genuine bug.

Comment From: rstoyanchev

The solution you reference in turn points to a Spring Framework issue. The https://github.com/spring-projects/spring-framework/issues/20239#issuecomment-562503768 at the end of the issue summarizes our perspective on logging with MDC.