Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

putCloseable should not remove the key from MDC if it was previously set to a different value #404

Open
mdpearson opened this issue Mar 15, 2024 · 1 comment · May be fixed by #405
Open

Comments

@mdpearson
Copy link

Our team wrote some code that broadly looked like this:

MDC.put("color", "red");

try(ignored = MDC.putCloseable("color", "green")) {
...
}

assertTrue(MDC.get("color", "green")) // fails, the key is deleted

It should be an easy patch to allow callers to nest putCloseable calls and get expected results; in fact, I'll go try to write one now.

Thank you very much, by the way, for SLF4j -- it's a wonderful tool. Cheers

@huxi
Copy link
Member

huxi commented Jul 30, 2024

We had the same issue and addressed it by writing our own NestedMDCClosable, essentially wrapping the MDC.

This should also be taken into account for the MDCAmbit proposal in #377 and #372.

Our use case are correlationIds in Services where a UUID is supposed to turn up in every log statement of a method call.

This works perfectly in case of a single service but breaks with the current MDCClosable implementation once one such service is directly calling another such service or methods of itself.

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 a pull request may close this issue.

2 participants