liveBook · Manning

Mapped diagnostic context

As explained in The Art of Code

Mapped Diagnostic Context is a per-execution logging context that automatically associates key-value information with log records.

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

How The Art of Code covers it

How deep it goes
Defines automatic contextual enrichment and its rationale but does not explain configuration or lifecycle mechanics.
Examples
Uses a transaction ID attached to every log produced during one execution flow.
What it assumes
Assumes familiarity with enterprise logging and log messages but explains the contextual-enrichment role directly.
What you can do after
Apply it to associate shared execution context with log records without repeating that context manually.
How it connects
Connects logging with transaction IDs, execution flows, exception handling, and logging pattern layouts.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of The Art of Code. The section links point to the parts of the book it draws on.