Mapped Diagnostic Context (MDC) enriches logging with per-execution key-value data, such as a transaction ID, so every log record in the same execution flow carries useful context automatically. section 7.2.3
Use MDC to make failure investigation more precise:
- Attach context once instead of repeating transaction or request information in every log statement. section 7.2.3
- Combine contextual data with a clear operation description and the exception object, preserving both failure meaning and diagnostic detail. section 7.2.3
- Keep code-specific details in the logging pattern layout when possible, so refactoring does not leave stale names in messages. section 7.2.3
Following one transaction
A transaction ID placed in the diagnostic context automatically appears on every log produced during that execution flow, allowing investigators to connect related events without manually repeating the ID. section 7.2.3
