Johann Pardanaud
03/24/2023, 10:31 AMrouting {
get("/some-route") {
MDC.put("foo", "bar") // Will it leak in successive requests for the same route?
println(MDC.getCopyOfContextMap())
delay(1)
println(MDC.getCopyOfContextMap()) // Should I use `withContext(MDCContext()) {}` here?
}
}
Should I do something like this?
routing {
get("/some-route") {
// Use MDCContext before modifying the MDC to ensure the data is restored
withContext(MDCContext()) {
MDC.put("foo", "bar")
println(MDC.getCopyOfContextMap())
// Use MDCContext before suspending the coroutine to ensure
// the data is still available when resuming
withContext(MDCContext()) {
delay(1)
println(MDC.getCopyOfContextMap())
}
}
}
}
As you can see, I’m a bit lost and I’m not sure when I need to use MDCContext
😬