-
Notifications
You must be signed in to change notification settings - Fork 457
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[mongodb] instrumentation loosing context #1688
Comments
(@david-luna We discussed on the SIG today.) @osherv You are the component owner for the OTel instrumentation-mongodb. The issue with the mongodb driver losing async context happens in mongodb@5 and mongodb@6. We are hoping to get a PR merged so that newer versions of mongodb v5 and v6 no longer have the issue. For earlier versions of mongodb v5 and v6 we could either:
@osherv, Do you have a preference? If I understood correctly on the SIG call today, I think @pichlermarc expressed a slight preference for doing (2). |
@david-luna Marc also asked about mongodb@4 status. Do you happen to know if it is instrumented? if it has the same issue? if it is even a relevant version of mongodb anymore? |
@trentm I've done tests on the repro repo and I could reproduce it down to version 4.0.0. Checking the instrumetation package I see Otel is instrumenting the version range Here is the results testing with v4.0.0
|
What version of OpenTelemetry are you using?
@opentelemetry/api: 1.4.1
@opentelemetry/auto-instrumentations-node: 0.39.2
@opentelemetry/sdk-metrics: 1.15.2
@opentelemetry/sdk-node: 0.41.2
and
mongodb: 5.8.1
What version of Node are you using?
All versions supported by
mongodb@5
>=14.20.1
What did you do?
Created an app which does queries to MongoDB and instrumented with Otel to get tracing of HTTP spans and their child database spans.
Repo with the code
https://github.com/david-luna/node-mongodb-native-async-resource
What did you expect to see?
When requesting the app concurrently I expect each HTTP span to have its child database span.
What did you see instead?
Database spans are grouped as children of few HTTP spans and the rest of HTTP spans have no child.
Additional context
I've done some research and found the issue is happening since
mongodb
driver uses a pool for connections queueing all command until a connection is available. Queued callbacks loose the execution context therefore mongodb spans are linked to the wrong parent HTTP span.I've made a small gist to show how a pool affects async context
https://gist.github.com/david-luna/8a66fc1308301f79af8bd2eb65bcbc07
Also I've created a repo with an app that reproduces the issue which is affecting not only Otel but other tracers like
elastic-apm-node
.https://github.com/david-luna/node-mongodb-native-async-resource
This could be fixed in
mongodb
itself if they do bind the execution context to the queued callbacks. I've opened an issue and created a PR to fix it but it's waiting for mongodb's team response.issue: https://jira.mongodb.org/browse/NODE-5639
PR: mongodb/node-mongodb-native#3871
Even if they accept the fix we probably will need to support earlier versions for customers that can't update to the ones with the fix.
The text was updated successfully, but these errors were encountered: