Sanjay Kasi
02/02/2023, 9:42 AMCallLogging
plugin to inject MDC values in the pipeline like so:
fun Application.module() {
install(CallLogging) {
mdc("clientIpAddress") { call ->
call.request.header("X-Forwarded-For") ?: "UNDEFINED"
}
}
}
We are generating a userId
within the route which needs to be added to MDC such that it is available outside the current co-routine context:
fun Application.myRoutes() {
routing {
get("/testMDC") {
MDC.putClosable("userId", "${UUID.randomUUID()}") // <-- This is thread local and does not carry onto other co-routines
}
}
}
The clientIpAddress
works fine and is logged throughout but userId
only logs in local context. Is there any work around for this?Sam
02/02/2023, 9:44 AMMDC
from Slf4J? You could take a look at https://github.com/Kotlin/kotlinx.coroutines/blob/master/integration/kotlinx-coroutines-slf4jSanjay Kasi
02/02/2023, 9:46 AMIsCorrect. Will check it out and revert. Thanks!from Slf4J?MDC
Pat Kujawa
02/23/2023, 5:09 AM