Hello, I’m trying to use Micrometer Tracing in Spring Boot 3.0 with Kotlin, but I think it’s not working the way I expected. From what I read, I thought that tracing information stored in coroutines contexts would flow through the different Threads of execution. But it looks like that once the thread changes, trace information is lost.
I’ve created this simple controller to test this:
@RestController
class TestController(val tracer: Tracer) {
private val logger: Logger = LoggerFactory.getLogger(this::class.java)
@GetMapping("/test")
suspend fun test() {
<http://logger.info|logger.info>("before: ${tracer.currentTraceContext().context()?.traceId()}")
delay(50)
<http://logger.info|logger.info>("after: ${tracer.currentTraceContext().context()?.traceId()}")
}
}
The second log statement reports a
null value for the traceId, because the Kotlin
delay
function caused a thread switch and the trace informations is lost,
Can anyone help here? Why is this happening? Is it by design? Is there something I can do to guarantee that the traceId is always present?