PropagationContextElement
class PropagationContextElement : ThreadContextElement<ContextSnapshot.Scope> , AbstractCoroutineContextElement
ThreadContextElement that ensures that contexts registered with the Micrometer Context Propagation library are captured and restored when a coroutine is resumed on a thread. This is typically being used for Micrometer Tracing support in Kotlin suspended functions.
It requires the io.micrometer:context-propagation library. If the org.jetbrains.kotlinx:kotlinx-coroutines-reactor dependency is also on the classpath, this element also supports Reactor Context.
PropagationContextElement can be used like this:
fun main() {
runBlocking(Dispatchers.IO + PropagationContextElement()) {
suspendingFunction()
}
}
suspend fun suspendingFunction() {
delay(1)
logger.info("Log statement with traceId")
}Content copied to clipboard
Author
Brian Clozel
Sebastien Deleuze
Since
7.0