Coder Social home page Coder Social logo

Comments (13)

AndrewLugg avatar AndrewLugg commented on May 31, 2024 3

If the mongodb-core plugin worked with Mongoose that would be great, I don't think a specific mongoose plugin is needed.

from dd-trace-js.

rochdev avatar rochdev commented on May 31, 2024

What is the version of the underlying mongodb-core module that is pulled as a transitive dependency?

from dd-trace-js.

AndrewLugg avatar AndrewLugg commented on May 31, 2024

I tried it with Mongoose 5.2.4, which uses mongodb-core 3.1.0

from dd-trace-js.

rochdev avatar rochdev commented on May 31, 2024

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?

from dd-trace-js.

rochdev avatar rochdev commented on May 31, 2024

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.

from dd-trace-js.

AndrewLugg avatar AndrewLugg commented on May 31, 2024

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.

from dd-trace-js.

rochdev avatar rochdev commented on May 31, 2024

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?

from dd-trace-js.

AndrewLugg avatar AndrewLugg commented on May 31, 2024

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

from dd-trace-js.

rochdev avatar rochdev commented on May 31, 2024

This shouldn't change the behavior. Is it possible maybe that this line const config = require('./src/config.js'); requires mongoose by indirection?

from dd-trace-js.

AndrewLugg avatar AndrewLugg commented on May 31, 2024

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":"?"}}

from dd-trace-js.

rochdev avatar rochdev commented on May 31, 2024

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.

from dd-trace-js.

rochdev avatar rochdev commented on May 31, 2024

This was fixed in #241

@AndrewLugg Can you confirm if it ended up working for you?

from dd-trace-js.

AndrewLugg avatar AndrewLugg commented on May 31, 2024

Yes this is working for us. Thank you.

from dd-trace-js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.