APM Nodejs Agent not intercepting MongoDB queries (no spans)

Kibana version: 7.2.0

Elasticsearch version: 7.2.0

APM Server version: 7.2.0

APM Agent language and version: elastic-apm-node 2.17.X

Original install method (e.g. download page, yum, deb, from source, etc.) and version: From npm package

Description of the problem including expected versus actual behavior. Please include screenshots (if relevant):
I use mongodb (https://www.npmjs.com/package/mongodb) npm package to connect to my database. Although I am using the latest version with elastic-apm-node, I can see the express HTTP calls, but no DB spans.

The top of the application is inside a www file and we did include the start() there. It sees all the HTTP requests, but no MongoDB queries. Moving the start elswere has no effect. Even adding a custom span around a DB query doesn't intercept the mongodb query.

The only special thing I see is that models are used to represent mongodb documents. Hence, instead of calling the driver directly, we abstract it behind a model. It shouldn't stop the APM agent from seeing the call anyway.

EDIT: We use the MongoClient object from mongodb llibrary

Errors in browser console (if relevant): None

Provide logs and/or server output (if relevant):
| setting default transaction name: POST /login { trans: 'df537a6y56y35523',
| parent: undefined,
| trace: '5ecc84e8426fghfghfghfghfg2d58a7ebe1' }
| sending transaction { trans: 'df537a6y56y35523',
| trace: '5ecc84e8426fghfghfghfghfg2d58a7ebe1' }
| ended transaction { trans: 'df537a6y56y35523',
| parent: undefined,
| trace: '5ecc84e8426fghfghfghfghfg2d58a7ebe1',
| type: 'request',
| result: 'HTTP 2xx',
| name: 'POST /login' }
| no active transaction found - cannot build new span
| intercepted call to http.request { id: null }

We don't see mongodb being intercepted at all

Resolved!

mongodb 3.3+ is not supported. I downgraded to 3.2.X and it worked.

Please update the doc to indicate the support limitation.

Hi Gumold

Welcome to the forum and thanks for reporting this issue.

Obviously we should support v3.3, and indeed we do include it in our test coverage. So somehow you must be using the mongodb client in a way we haven't covered in our tests.

To be able to ensure full support for v3.3, I'd like to be able to reproduce the bug you discovered. Would it be possible for you to share a little more details - preferably a code snippet that reproduces the problem - so that we can reproduce the bug on our end?

/thomas

Hi Thomas,

Thanks for the prompt answer. Reading the release notes of 3.3, it is mentioned that mongodb-core is merged in node-mongodb-native. Could this be releated (https://github.com/mongodb/node-mongodb-native/releases/tag/v3.3.0)?

I will push a github project showcasing the problem.

Best,
G

Ah hang on, you might be on to something there. I was wrong in assuming it was part of our test coverage as it's actually only mongodb-core we're testing. So you're right that it's not currently supported - that's why.

I'll open an issue to make sure we add support for it and in the meantime update our docs

1 Like

Here's the issue for adding support for newer mongodb versions:

1 Like

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.