Span in Kotlin `withTimeout` has wrong parent
Tracer Version(s)
1.54.0
Java Version(s)
21.0.7
JVM Vendor
Other (please specify in comments)
Bug Report
Hi! I have the following code in a Kotlin Ktor server application, when handling an incoming HTTP request:
post("/foo") {
span("withTimeoutOutside") {
delay(100)
withTimeout(500) {
span("withTimeoutInside") {
delay(100)
}
}
}
}
I'd expect the root span (for the HTTP request) to have a child of withTimeoutOutside, which has a child of withTimeoutInside. Instead, what I see is this:
This is possibly related to the fixes put in place for https://github.com/DataDog/dd-trace-java/issues/7215.
Let me know if you need me to provide anything else to help with this.
Thanks in advance!
(Am running on OpenJDK 64-Bit Server VM Temurin-21.0.7+6)
Expected Behavior
I'd expect the root span (for the HTTP request) to have a child of withTimeoutOutside, which has a child of withTimeoutInside.
Reproduction Code
No response
Hi @yonigibbs - could you attach a buildable example? That would help progress this issue
The changes in #7215 improved context propagation for Kotlin coroutines in general, but it's possible there's an edge-case in how our OpenTelemetry compatibility layer interacts with KTor, specifically KTor's span extension methods that use the OpenTelemetry API to create and activate spans.
Sure, here's a repo that should allow you to reproduce the issue: https://github.com/yonigibbs/dd-coroutines.
While trying to create this I discovered that it seems to be related to ktor's CallLogging plugin. More details in the README in the repo.
Lemme know if I can help in any way, and thanks for taking the time to reply 👍
Thanks for the example and extra info @yonigibbs