Hello, I'm looking to use MDC in my Kotlin backend...
# coroutines
h
Hello, I'm looking to use MDC in my Kotlin backend and I have a question on how I could implement it. I currently have just simple Lambdas, so my code is something like
Copy code
override fun handleRequest(inputStream: InputStream, outputStream: OutputStream, context: Context) = runBlocking(Dispatchers.Default) {
        stuff()
}
From a few implementations I see, it seems it is a simple addition of
MDCContext()
to
Dispatchers.Default
, so
Copy code
override fun handleRequest(inputStream: InputStream, outputStream: OutputStream, context: Context) = runBlocking(Dispatchers.Default + MDCContext()) {
        stuff()
}
Does this make sense to you?
d
Yes, that's what we are doing as well (
Dispatchers.Default + MDCContext()
).
gratitude thank you 1
h
According to https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-slf4j/kotlinx.coroutines.slf4j/-m-d-c-context/, you need to set up the context before you set it up - or do you do the pattern suggested where they launch the context and then you update it within the function?