Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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!

question from:https://stackoverflow.com/questions/65621350/operatorslift-good-idea-for-mdc-logging

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
377 views
Welcome To Ask or Share your Answers For Others

1 Answer

This is the approach that was initially taken by Sleuth, via Hooks.onEachOperator. However, this is very costly and probably not worth it if you only need logging/MDC on a subset of operations in you reactive pipeline. Not to mention that this approach not only impacts reactive steps defined by you, but also any other library / framework.

The recommendation is there for a reason: better control, less impact and a more explicit approach.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...