Capture the MDC and thread name before queueing the event - #32
Merged
Merged
Conversation
…nder thread Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Reported in #23.
append()queues theILoggingEventas is and everything is read from it later, on the sender thread. Logback fills the MDC map and the thread name of aLoggingEventlazily, from whichever thread first asks for them, so by the timebuildPostData()runs, the logging thread's MDC is gone:metanever carries the configuredmdcFieldsunless the flush happens to run on the logging thread itself (which is why the integration tests, which callflush()synchronously, never noticed), andruntime.threadreports the sender thread instead of the thread that logged.The fix is what logback's own
AsyncAppenderdoes before handing an event to another thread:append()now callsevent.prepareForDeferredProcessing(), which captures the formatted message, the thread name and the MDC map while the event is still on the logging thread. Caller data is deliberately not captured here, since computing it walks the stack on every log call and logback keeps that opt-in for the same reason.The first commit is the failing test on its own and is expected to fail CI; the second commit makes it pass.
🤖 Generated with Claude Code