how can i retrieve MDC from a CoroutineContext in a exception handler ?
the code looks like so currently
Copy code
private val exceptionHandler = CoroutineExceptionHandler { context, e -> GlobalScope.launch(MDCContext() + context) {
can i somehow do
context.getCopyOfContextMap()
?
o
oshai
11/12/2020, 7:44 PM
How about keeping MDCContext() in a var?
n
Nikky
11/12/2020, 7:52 PM
the issue seems to be that on coroutine boundary the contextMap from the coroutineContext is used to restore the MDC
ie. when you put
MDC.put("extra", "value")
inside the coroutineScope and before a suspending call
then after that call the new value will be gone
so i tried something where i manually "save" the MDC state to the coroutineContext