MDCContext
Thread-safe MDC (Mapped Diagnostic Context) management for async operations.
SLF4J MDC is thread-local, so context is lost when work moves across threads. This utility captures, restores, and propagates MDC state to ensure consistent logging context in Future-based and ExecutionContext-based pipelines.
Attributes
- Graph
-
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
MDCContext.type
Members list
Value members
Concrete methods
Capture the current thread's MDC context as an immutable map.
Capture the current thread's MDC context as an immutable map.
Attributes
- Returns
-
a snapshot of all MDC key-value pairs, or an empty map if none are set
Remove specific keys from the current thread's MDC.
Remove specific keys from the current thread's MDC.
Value parameters
- keys
-
the MDC keys to remove
Attributes
Wrap an ExecutionContext so that MDC context is captured at submission time and restored on the executing thread before each runnable runs.
Wrap an ExecutionContext so that MDC context is captured at submission time and restored on the executing thread before each runnable runs.
Value parameters
- underlying
-
the execution context to wrap
Attributes
- Returns
-
an MDC-preserving execution context
Map over a Future while preserving the caller's MDC context on the callback thread.
Map over a Future while preserving the caller's MDC context on the callback thread.
Value parameters
- ec
-
implicit execution context for the map callback
- future
-
the future to wrap
Attributes
- Returns
-
a future whose map callback runs with the caller's MDC context
Replace the current thread's MDC context with the given map.
Replace the current thread's MDC context with the given map.
Value parameters
- context
-
the MDC key-value pairs to install
Attributes
Execute a block with the given MDC context, restoring the previous context afterward.
Execute a block with the given MDC context, restoring the previous context afterward.
Value parameters
- block
-
the code to execute
- context
-
MDC key-value pairs to set during execution
Attributes
- Returns
-
the result of
block
Execute a block with additional MDC values merged into the current context. The previous context is restored afterward.
Execute a block with additional MDC values merged into the current context. The previous context is restored afterward.
Value parameters
- block
-
the code to execute
- values
-
key-value pairs to add to the current MDC
Attributes
- Returns
-
the result of
block