Skip to content
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

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

Open
1 of 3 tasks
evgeni-k opened this issue Nov 25, 2019 · 9 comments
Open
1 of 3 tasks

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

evgeni-k opened this issue Nov 25, 2019 · 9 comments
Assignees
Labels
agent-nodejs Make available for APM Agents project planning. bug

Comments

@evgeni-k
Copy link

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
@evgeni-k evgeni-k changed the title there is no spans for queries w/out exec() for mongoose 5.6.3 there are no spans for queries w/out exec() for mongoose 5.6.3 Nov 25, 2019
@Qard
Copy link
Contributor

Qard commented Nov 27, 2019

This is an unresolved issue with Promise Hooks in V8 and async_hooks in Node.js core. nodejs/node#22360

The only way to make this work is to fix it in V8.

@evgeni-k
Copy link
Author

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.

@sibelius
Copy link
Contributor

does this also affects .aggregate?

@Systerr
Copy link

Systerr commented Sep 22, 2020

nodejs/node#22360 (comment) async_hooks was fixed

@Qard
Copy link
Contributor

Qard commented 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.

@trentm trentm added [zube]: Inbox bug agent-nodejs Make available for APM Agents project planning. and removed [zube]: Inbox labels Nov 10, 2020
@david-luna
Copy link
Member

david-luna commented Oct 27, 2023

Just came across this issue and did some test to see if still apply. Mongoose is added to the support list in elastic-apm-agent@4 This new version does not support node <14 though.

I've used this example from the main branch to test also with the latest version of the 3.x branch.

req.waterfall:
    trace 9fe140
    `- transaction ed477c "t1" (34.813ms, outcome=unknown)
       `- span 8fac72 "example-trace-mongoose.people.insert" (1ms, mongodb)
       `- span bc7a36 "example-trace-mongoose.people.find" (1ms, mongodb)
       `- span b84aca "example-trace-mongoose.people.delete" (1ms, mongodb)
       `- span ec1f92 "admin.$cmd.endSessions" (0ms, mongodb, sync)

Mongoose eersions tested were: 7.6.3, 6.12.2, 5.13.21 & 5.6.3

So I'm inclined to close this one @evgeni-k if there is nothing else to look

@david-luna david-luna self-assigned this Oct 27, 2023
@sibelius
Copy link
Contributor

this is breaking for

mongoose 8.03
mongodb 6.2.0

@ccstuff
Copy link

ccstuff commented Feb 22, 2024

this is breaking for这是打破

mongoose 8.03 猫鼬 8.03 mongodb 6.2.0

me too.

[email protected]
mongodb: 6.2.0

@sibelius
Copy link
Contributor

It is working fine on latest version of packages

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
agent-nodejs Make available for APM Agents project planning. bug
Projects
None yet
Development

No branches or pull requests

7 participants