Skip to content

Capture the MDC and thread name before queueing the event - #32

Merged
PetrHeinz merged 2 commits into
mainfrom
claude/gh-23-mdc-snapshot
Sep 25, 2026
Merged

PetrHeinz merged 2 commits into
mainfrom
claude/gh-23-mdc-snapshot

Conversation

@PetrHeinz

Copy link
Copy Markdown
Member

Reported in #23.

append() queues the ILoggingEvent as is and everything is read from it later, on the sender thread. Logback fills the MDC map and the thread name of a LoggingEvent lazily, from whichever thread first asks for them, so by the time buildPostData() runs, the logging thread's MDC is gone: meta never carries the configured mdcFields unless the flush happens to run on the logging thread itself (which is why the integration tests, which call flush() synchronously, never noticed), and runtime.thread reports the sender thread instead of the thread that logged.

The fix is what logback's own AsyncAppender does before handing an event to another thread: append() now calls event.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

PetrHeinz and others added 2 commits September 25, 2026 16:47
…nder thread

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@PetrHeinz
PetrHeinz marked this pull request as ready for review September 25, 2026 15:28
@PetrHeinz
PetrHeinz merged commit b4c7df8 into main Sep 25, 2026
5 checks passed
@PetrHeinz
PetrHeinz deleted the claude/gh-23-mdc-snapshot branch September 25, 2026 15:40
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.

1 participant