# APM Nodejs Agent not intercepting MongoDB queries (no spans)

**URL:** <https://discuss.elastic.co/t/apm-nodejs-agent-not-intercepting-mongodb-queries-no-spans/200338>\
**Category:** APM\
**Tags:** nodejs\
**Created:** [September 20, 2019, 4:40am UTC](https://discuss.elastic.co/t/apm-nodejs-agent-not-intercepting-mongodb-queries-no-spans/200338 "2019-09-20T04:40:01Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![gumold](https://avatars.discourse-cdn.com/v4/letter/g/f9ae1b/32.png) [@gumold](https://discuss.elastic.co/u/gumold)\
**Post date:** [September 20, 2019, 4:40am UTC](https://discuss.elastic.co/t/apm-nodejs-agent-not-intercepting-mongodb-queries-no-spans/200338/1 "2019-09-20T04:40:01Z")

</div>

**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](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

---

<div class="post-metadata">

**Author:** ![gumold](https://avatars.discourse-cdn.com/v4/letter/g/f9ae1b/32.png) [@gumold](https://discuss.elastic.co/u/gumold)\
**Post date:** [September 20, 2019, 5:00am UTC](https://discuss.elastic.co/t/apm-nodejs-agent-not-intercepting-mongodb-queries-no-spans/200338/2 "2019-09-20T05:00:25Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![wa7son](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wa7son/32/21259_2.png) [@wa7son](https://discuss.elastic.co/u/wa7son)\
**Post date:** [September 20, 2019, 5:47am UTC](https://discuss.elastic.co/t/apm-nodejs-agent-not-intercepting-mongodb-queries-no-spans/200338/3 "2019-09-20T05:47:15Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![gumold](https://avatars.discourse-cdn.com/v4/letter/g/f9ae1b/32.png) [@gumold](https://discuss.elastic.co/u/gumold)\
**Post date:** [September 20, 2019, 11:49am UTC](https://discuss.elastic.co/t/apm-nodejs-agent-not-intercepting-mongodb-queries-no-spans/200338/4 "2019-09-20T11:49:00Z")

</div>

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](https://github.com/mongodb/node-mongodb-native/releases/tag/v3.3.0))?

I will push a github project showcasing the problem.

Best,  
G

---

<div class="post-metadata">

**Author:** ![wa7son](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wa7son/32/21259_2.png) [@wa7son](https://discuss.elastic.co/u/wa7son)\
**Post date:** [September 20, 2019, 12:15pm UTC](https://discuss.elastic.co/t/apm-nodejs-agent-not-intercepting-mongodb-queries-no-spans/200338/5 "2019-09-20T12:15:57Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![wa7son](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wa7son/32/21259_2.png) [@wa7son](https://discuss.elastic.co/u/wa7son)\
**Post date:** [September 20, 2019, 12:45pm UTC](https://discuss.elastic.co/t/apm-nodejs-agent-not-intercepting-mongodb-queries-no-spans/200338/6 "2019-09-20T12:45:11Z")

</div>

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

> <https://github.com/elastic/apm-agent-nodejs/issues/1368>

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [October 11, 2019, 8:45am UTC](https://discuss.elastic.co/t/apm-nodejs-agent-not-intercepting-mongodb-queries-no-spans/200338/7 "2019-10-11T08:45:14Z")

</div>

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