question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

there are no spans for queries w/out exec() for mongoose 5.6.3

See original GitHub issue

Describe the bug The library does not automatically creates span if there is no explicit exec() function call on query object.

Mongoose uses native Promise.

mongoose.Promise = global.Promise;

Following code snippet is instrumented perfectly and span is created

async function test() {
    const result = await Model.find().exec();
    console.log(result);
}

This code snippet cannot be automatically instrumented (span cannot be created)

async function test() {
    const result = await Model.find();
    console.log(result);
}

Mongoose automatically calls exec when then is called https://github.com/Automattic/mongoose/blob/5.6.3/lib/query.js#L4297-L4299

To Reproduce

Run code snippets below in your app. If you run with explicit exec call then span is created otherwise it won’t.

Expected behavior

Span should be created w/ and w/out explicit exec function call.

Environment (please complete the following information)

  • OS: Mac OS 10.15.1
  • Node.js version: 12.13.0
  • APM Server version: 7.4.0
  • Agent version: 3.1.0

How are you starting the agent? (please tick one of the boxes)

  • Calling agent.start() directly (e.g. require('elastic-apm-node').start(...))
  • Requiring elastic-apm-node/start from within the source code
  • Starting node with -r elastic-apm-node/start

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
evgeni-kcommented, Nov 28, 2019

Thank you for your reply. Probably it makes sense to update docs to explicitly highlight that fact about custom thenable.

Feel free to close the ticket.

0reactions
Qardcommented, Sep 22, 2020

Yep, I fixed the issue in V8 a few months ago. It’s in Node.js 14.x. Still waiting on the backport to land in 12.x.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Mongoose v6.8.2: Queries
A mongoose query can be executed in one of two ways. First, if you pass in a callback function, Mongoose will execute the...
Read more >
mongoose.Query.prototype.exec() patching not working with ...
I solved it by saving the reference to original exec() inside the Query object instead of just a local variable and calling that...
Read more >
Express Tutorial Part 3: Using a Database (with Mongoose)
In this article, we've learned a bit about databases and ORMs on Node/Express, and a lot about how Mongoose schema and models are...
Read more >
How find() Works in Mongoose | www.thecodebarbarian.com
But there's some confusion about Model.find() vs Query#find() , setting ... check out run-rs, it downloads and runs MongoDB for you with no...
Read more >
Introduction to Mongoose for MongoDB - freeCodeCamp
Mongoose is an Object Data Modeling (ODM) library for MongoDB and Node.js. ... documents can vary as it is not enforced like SQL...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found