gavvvr
05/14/2025, 12:00 AMAleksei Tirman [JB]
05/14/2025, 8:15 AMthis
within the route handler isn't a coroutine scope, so the launch
is executed from the scope of the embeddedServer
. As a workaround, you can define a coroutine scope in the route handler:
get("/") {
coroutineScope {
launch {
println("Is null with Ktor v3: " + MDC.get(CLIENT_ID_MDC_KEY))
}
call.respondText("Retrieved as expected: " + MDC.get(CLIENT_ID_MDC_KEY))
}
}
gavvvr
05/14/2025, 9:58 AMthis
has a SupervisorJob
type. Looks like things have changed since Ktor v2, I left some more details in the issue comments. After some experiments I think, it's generally not a problem for me. I can indeed call call.launch{...}
from routing or start another coroutine context deep in my business logic layer, this way MDC context gets properly inherited anyway.