Hello, I’m trying to use Micrometer Tracing in Spr...
# spring
p
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:
Copy code
@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?
r
I think this doesn't work fully automatically out of the box yet, if I understand this issue report: https://github.com/spring-projects/spring-boot/issues/33372#issuecomment-1331448075 (linking to a specific comment where the discussion starts involving Kotlin, but the comments further on are relevant as well)
1379 Views