Project Reactor documentation suggests the following pattern for MDC logging:
.doOnEach(logOnNext(r -> LOG.debug("found restaurant {} for ${}", r.getName(), r.getPricePerPerson())))
To avoid having to wrap each logging call, would a custom subscriber, populating the MDC from the currentContext before each signal, added using Hooks.onEachOperator(Operators.lift(...)) be a good idea?
My main conerns are:
1.) The cost of populating the MDC before every signal, even if there is no logging happening.
2.) Operator fusion: Does Operators.lift(...) on each operator effectively disable operator fusion? Attempting a quick test with StepVerifier#expectFusion seems to indicate that. If this is true, how much of a performance hit is this, in practice?
Any input is appreciated!