How to propagate Context to reactive/coroutine MongoDB commands? #9866
-
Hi everyone! I am quite novice in OpenTelemetry, previously worked with the Python packages and now I am trying to configure the same setup, but in Kotlin/JVM. I am using Ktor with MongoDB Kotlin Driver in my project. In order to instrument both of them I use ktor-2.0 and mongo-3.1 (library) respectively. I have noticed that with such a combination I get different trace IDs:
In comparison with the sync MongoDB driver the IDs are the same:
While debugging I've noticed that I've tried to wrap the call with Here's an MVP to reproduce the problem: opentelemetry-test.zip (MongoDB on the localhost is required). |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
You might have better luck with java agent. As you noticed the context is lost before |
Beta Was this translation helpful? Give feedback.
You might have better luck with java agent. As you noticed the context is lost before
TracingCommandListener
to make it work we'd need to figure out how to get the context there. I think the context is lost in https://github.com/mongodb/mongo-java-driver/blob/02a61642394ca707beb30947101afb5b8c6d36b7/driver-core/src/main/com/mongodb/internal/connection/DefaultConnectionPool.java#L1286 in java agent we can wrap the task object and use that to preserve the context but for library instrumentation our options are much more limited. One option to make it work would be to rewrite the instrumentation in a different way. Instead of usingTracingCommandListener
one could attempt to wrap the mongo r…