-
Notifications
You must be signed in to change notification settings - Fork 295
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
App Analytics doesn't seem to be working with Mongoose #1021
Comments
This is most certainly a bug as
This is not necessarily the case. When the tracer is initialized after an instrumented module, it's possible the instrumentation will still work but with unexpected behavior. Can you share the top of your entry point, just to be sure the order is 100% correct? |
@rochdev here it is: process.env.NODE_ENV = process.env.NODE_ENV || 'development';
import config from 'config-dug'; // No mongoose/mongo dependency
import axios from 'axios'; // No mongoose/mongo dependency
import './lib/apm/analytics'; // This file contains the APM initialization code shown above
import createApp from './app' // This file contains the Mongoose initialization call |
Do you know if the underlying call is using cursors? It looks like cursors don't currently add the analytics tag, so that may be why it's not working. You would be able to know if it's a cursor by checking if the Mongo span contains a |
@rochdev I poked around and there seem to be those cursor tags on most or all of our MongoDB traces. I think there's a plot twist though: I'm looking closer and I don't see a single update-style call in our MongoDB trace history (going back 15 days). We associate logs and traces, and on logs where an update happened, the trace just has a blank spot where the MongoDB update would have gone. So maybe there's a couple of issues happening here? |
It's possible it's because of how we track cursors which might ignore the actual start/end of the operation. I'll have to look into it. Is this something you can reproduce minimally in a snippet? This would help me figure out the exact issue and set up a test case for it. |
👍 I'll give it a shot when I have some time and get back to you |
The below snippet replicates the first issue (cursored queries not showing up in app analytics) but not the second issue. I'll have to see if there's anything special about our configuration and come back later. (async () => {
const tracer = require('dd-trace');
tracer.init({
service: 'test-service',
enabled: true,
tags: {
environment: 'test'
},
env: 'test',
analytics: true
});
tracer.use('mongodb-core', { analytics: true });
const mongoose = require('mongoose');
const mongooseInstance = new mongoose.Mongoose();
const db = await mongooseInstance.connect('mongodb://localhost:27017/testService?retryWrites=true');
const schema = new mongoose.Schema({ foo: 'string' });
const model = db.model('testcollection', schema);
await tracer.trace('test-trace', async () => {
const testDocument = await model.create({
foo: 'bar'
});
await model.findById(testDocument.id);
console.log('done!');
});
})(); edit: In fact, even if I put all the Mongo initialization stuff above the tracer initialization stuff, the update spans ship fine. |
Fixed in #1159 |
Describe the bug
We added
dd-trace
to one of our projects and attempted to enable App Analytics onmongodb-core
. Traces are captured and appear in Datadog, and analyzed spans for the top span are captured, but we don't seem to get analyzed spans from Mongo queries.I believe this is a bug because:
we enabled analytics for other DBs in the same exact manner, and we do get analyzed spans for them (see config below).
traces for Mongo are captured and sent to Datadog as expected, so the tracer is surely being initialized before it's imported.
Environment
Linux on Docker
12.18.2
5.8.7
0.22.2
latest
The library is working awesome overall, thanks for all the hard work you put into it! Let me know if I can provide any more info.
The text was updated successfully, but these errors were encountered: