how can i retrieve MDC from a CoroutineContext in ...
# coroutines
n
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()
  ?
l
It's unclear what MDC is, but docs about CoroutineContext online explain how to put custom stuff in it and how to get it back.
g
MDC is Mapped Diagnostic Context, integration with sl4j logging
how can i retrieve MDC from a CoroutineContext in a exception handler
Maybe I misunderstood your case, but why not just
Copy code
CoroutineExceptionHandler { context, e ->
val mdcMap = 
context[MDCContext]?.contextMap
}
n
i arrived at this.. and i hope it ends up working..
MDCContext(context[MDCContext.Key]?.contextMap)
g
So your goal is copy it? Why not just use directly?
n
the goal is to only extract the MDCContext out of the
context
variable so that the logged error will have the mdc context from where the exception comes.. hopefully