class MDCContext(val contextMap: MDCContextMap = MDC.getCopyOfContextMap()) : AbstractCoroutineContextElement, ThreadContextElement<MDCContextMap>

MDC context element for CoroutineContext.


MDC.put("kotlin", "rocks") // Put a value into the MDC context

launch(MDCContext()) { { "..." } // The MDC context contains the mapping here

Note that you cannot update MDC context from inside the coroutine simply using MDC.put. These updates are going to be lost on the next suspension and reinstalled to the MDC context that was captured or explicitly specified in contextMap when this object was created on the next resumption. Use withContext(MDCContext()) { ... } to capture updated map of MDC keys and values for the specified block of code.



the value of MDC context map. Default value is the copy of the current thread's context map that is acquired via MDC.getCopyOfContextMap.


Link copied to clipboard
constructor(contextMap: MDCContextMap = MDC.getCopyOfContextMap())


Link copied to clipboard


Link copied to clipboard

The value of MDC context map.