What is the version of the underlying mongodb-core module that is pulled as a transitive dependency?
I tried it with Mongoose 5.2.4, which uses mongodb-core 3.1.0
I'll have to try it. I wonder if it's in the way that mongoose uses mongodb-core.
Is this issue basically just to fix the mongodb-core plugin or are you looking for an actual mongoose plugin as well?
If the mongodb-core plugin worked with Mongoose that would be great, I don't think a specific mongoose plugin is needed.
Just wrote a simple test case using findOne() and I get a span as expected.
Are you loading mongoose before or after calling tracer.trace()? Also, are you using import or require? Sometimes the order will change once transpiled when using import because of hoisting.
I am using Express, and Mongoose, Express tracing is working fine, and I get the http requests too, but mongo does nothing.
Here is a copy of the order I am bringing in the my libraries:
const when = require('when');
const request = require('request');
const requestRetry = require('requestretry');
const ioredis = require('ioredis');
const compression = require('compression');
const config = require('./src/config.js');
const tracer = require('dd-trace').init({
service : 'ls-service-'+ config.ENVIRONMENT,
//hostname: 'service.' + config.ENVIRONMENT,
hostname: 'host.docker.internal',
port: 8126,
debug: true,
});
tracer.use('express');
//tracer.trace();
const mongoose = require('mongoose');
const express = require('express');
const app = express();
const bodyParser = require('body-parser');
This is the one I just tested adding tracer.trace(); and I get a deprecatin warning for it saying "Please use tracer.startSpan() and tracer.scopeManager() instead.See: https://datadog.github.io/dd-trace-js/#manual-instrumentation."
I also tried adding tracer.use('mongodb-core'); but from what I understand, it doesn't matter if I have plugins defaulted to true.
It is correct that tracer.use() is not necessary if you don't explicitly disable all plugins in the configuration.
The code from the snippet you provided seems correct. Would you be able to provide a small sample of Mongoose code that you would expect to get a span but doesn't?
Also, which version of the tracer are you using?
I decided to try it on a different server that has a more simplified layout. And it is working with Mongoose and Express. The difference is that it has all of its functions in the 1 file, and the model as a separate file. The service it wasn't working with, has the express message handlers in an a separate file, which call the models in.
Server1 (not working)
app.js
---> Message-handlers.js
\---> Models.js
Server2 (working)
app.js
---> Models.js
I am using dd-trace version 0.5.3
This shouldn't change the behavior. Is it possible maybe that this line const config = require('./src/config.js'); requires mongoose by indirection?
Thank you. That fixed it, it now shows up. All my tests I hadn't put it above config as I wanted the environment from the config.
It doesn't seem to grab the parent span/scope with it, all the Mongo queries are separately listed in the traces. Would that be because of the extra tier of requires?
It works perfectly on our "Server2", and properly attaches the Mongo query to the Express request.
I should also mention the Mongo queries show up, but they have long strings attached to them, which breaks the formatting on the Datadog APM page.
Here is a sample name:
find database-stage.organisations {"_id":{"_bsontype":"?","id":{"0":"?","1":"?","2":"?","3":"?","4":"?","5":"?","6":"?","7":"?","8":"?","9":"?","10":"?","11":"?","asciiSlice":"?","base64Slice":"?","latin1Slice":"?","hexSlice":"?","ucs2Slice":"?","utf8Slice":"?","asciiWrite":"?","base64Write":"?","latin1Write":"?","hexWrite":"?","ucs2Write":"?","utf8Write":"?","parent":{},"offset":"?","copy":"?","toString":"?","equals":"?","inspect":"?","compare":"?","indexOf":"?","lastIndexOf":"?","includes":"?","fill":"?","write":"?","toJSON":"?","slice":"?","readUIntLE":"?","readUIntBE":"?","readUInt8":"?","readUInt16LE":"?","readUInt16BE":"?","readUInt32LE":"?","readUInt32BE":"?","readIntLE":"?","readIntBE":"?","readInt8":"?","readInt16LE":"?","readInt16BE":"?","readInt32LE":"?","readInt32BE":"?","readFloatLE":"?","readFloatBE":"?","readDoubleLE":"?","readDoubleBE":"?","writeUIntLE":"?","writeUIntBE":"?","writeUInt8":"?","writeUInt16LE":"?","writeUInt16BE":"?","writeUInt32LE":"?","writeUInt32BE":"?","writeIntLE":"?","writeIntBE":"?","writeInt8":"?","writeInt16LE":"?","writeInt16BE":"?","writeInt32LE":"?","writeInt32BE":"?","writeFloatLE":"?","writeFloatBE":"?","writeDoubleLE":"?","writeDoubleBE":"?","swap16":"?","swap32":"?","swap64":"?","toLocaleString":"?"},"toHexString":"?","get_inc":"?","getInc":"?","generate":"?","toString":"?","toJSON":"?","equals":"?","getTimestamp":"?","generationTime":"?"}}
It doesn't seem to grab the parent span/scope with it, all the Mongo queries are separately listed in the traces.
I see you are using when which handles promises in a way that is not compatible with context propagation. We will look at patching the most popular promise libraries eventually, but for the moment this is unfortunately not supported. Using the native Promise if you can would fix the issue. Otherwise you could also propagate the context manually as well.
I should also mention the Mongo queries show up, but they have long strings attached to them, which breaks the formatting on the Datadog APM page.
This is definitely not the expected behavior. While the format of the string is correct, it shouldn't contain all these buffer methods. I'll have to take a look.
This was fixed in #241
@AndrewLugg Can you confirm if it ended up working for you?
Yes this is working for us. Thank you.
Most helpful comment
If the mongodb-core plugin worked with Mongoose that would be great, I don't think a specific mongoose plugin is needed.