For each ingressing request to ktor server, are th...
# server
j
For each ingressing request to ktor server, are they started in their own coroutine, with their own coroutine context? We are seeing some rather strange behavior in MDC logging where when we add a header value that is unique to every request or null - it is somehow being relogged for requests that do not match
🤨 2
Some more hopefully helpful context: I happened to be checking some logs while testing something else out and noticed that an old trace ID was somehow reused. On inspection, this seems to only be happening with requests that don't have a header value set (liveness probes) and the Otel library is setting the value appropriately (see the column to the right of the last highlighted request)
The odd part about this, is there's a gap in the processing thread, but I don't have coroutine ids logged anywhere. Could a coroutine or its context somehow be reused after the first request is terminated?
j
Are you using "coroutine-aware" MDC e.g. https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-slf4j/kotlinx.coroutines.slf4j/-m-d-c-context/ - if you use the regular MDC it will attach to a thread, and thus the set, and in-particular clear, won't work as you might expect.
âž• 2
💡 1
j
Yes, since we're logging this by using the
CallLogging
module, which (if I'm reading the source correctly) uses the coroutine aware MDC lib
Any more thoughts? We've been using the correct library and still see the issue
More importantly, can someone confirm that all requests coming into Ktor are processed as their own coroutines with their own contexts? This is coming up because part of my work involves adding some more information into the context.