Skip to content

Conversation

@mwootendev
Copy link

Updates the NDC class in slf4j-ext to include a static contains() method
that can check the existing nested diagnostic context for the presence
of a value.

Added unit tests to test the new NDC.contains() method.

Updates the NDC class in slf4j-ext to include a static contains() method
that can check the existing nested diagnostic context for the presence
of a value.

Added unit tests to test the new NDC.contains() method.

Signed-off-by: Michael Wooten <mwooten.dev@gmail.com>
@ceki
Copy link
Member

ceki commented Sep 10, 2021

@mwootendev Can you kindly describe what type of problems are better solved by NDC instead of MDC?

@mwootendev
Copy link
Author

@ceki I've actually found the NDC useful for tracing a path through a system. It serves as a good "how did we get here", especially when there are multiple paths that interface with some common services. For instance, if there is a low-level service for looking up a user, there will probably be multiple higher-level parts of the system that utilize it. If each layer pushes its own NDC context you get a fairly accurate picture of how you got there. For instance, the same logging statement in that user service may end up with different NDCs of [ORDERS USER LOOKUP], [USER REGISTRATION LOOKUP], and [USER ACTIVATION LOOKUP] depending on how that service was reached. This is especially useful for log statements that are not errors and do not have a stack trace.

I tend to differentiate MDC as the "what did we get here", like an order number or user ID. Having the context of "how" can often greatly enhance the value of the "what."

@ceki
Copy link
Member

ceki commented Sep 10, 2021

@mwootendev OK, I am still trying to understand. So [ORDERS USER LOOKUP], [USER REGISTRATION LOOKUP], and [USER ACTIVATION LOOKUP] are NDC values?

If so, [ORDERS USER LOOKUP] describes the ORDERS -> USER -> LOOKUP path?

@mwootendev
Copy link
Author

@ceki Yes, that would be correct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants