# Node.js Agent not instrumenting Mongoose

**URL:** <https://discuss.elastic.co/t/node-js-agent-not-instrumenting-mongoose/201254>\
**Category:** APM\
**Tags:** nodejs\
**Created:** [September 26, 2019, 2:17pm UTC](https://discuss.elastic.co/t/node-js-agent-not-instrumenting-mongoose/201254 "2019-09-26T14:17:52Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![hpinhal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hpinhal/32/54944_2.png) [@hpinhal](https://discuss.elastic.co/u/hpinhal)\
**Post date:** [September 26, 2019, 2:17pm UTC](https://discuss.elastic.co/t/node-js-agent-not-instrumenting-mongoose/201254/1 "2019-09-26T14:17:52Z")

</div>

Hi guys,

I'm running a trial on Elastic Cloud and I'm trying to instrument a Node.js API.  
In general, the transactions are showing just fine.

However, I think there's two items that are not working well.

1. Mongoose not being instrumented  
I see other modules (ie session) which are using the same mongo connection that get database spans.  
Some calls do get instrumented, like `new Model({}).save()`. On the other hand, stuff like `find` or `findOneAndUpdate` are not getting instrumented.

2. No "own" code spans  
Please correct me if I am wrong but the agent is supposed to trace our own code.

Some details:  
Node version: 12.7.0  
Agent version: 2.17.0  
Mongoose version: 5.3.14

Thanks in advance for any possible insight here.

Cheers,  
Helder

---

<div class="post-metadata">

**Author:** ![karlpokus](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/karlpokus/32/48868_2.png) [@karlpokus](https://discuss.elastic.co/u/karlpokus)\
**Post date:** [September 26, 2019, 7:26pm UTC](https://discuss.elastic.co/t/node-js-agent-not-instrumenting-mongoose/201254/2 "2019-09-26T19:26:51Z")

</div>

Hi @hpinhal

We can see find calls just fine using mongoose and elastic-apm-node v2.16.2. We're using the ES6 import fix with `elastic-apm-node/start` to make sure we import the lib at the very top. Maybe that is your issue?

---

<div class="post-metadata">

**Author:** ![hpinhal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hpinhal/32/54944_2.png) [@hpinhal](https://discuss.elastic.co/u/hpinhal)\
**Post date:** [September 26, 2019, 8:08pm UTC](https://discuss.elastic.co/t/node-js-agent-not-instrumenting-mongoose/201254/3 "2019-09-26T20:08:01Z")

</div>

Unfortunately no luck.  
We're using Typescript, and the import just like mentioned in the documentation.  
It's not the very very first import item tho. `dotenv` comes first but that shouldn't be causing this.

I'm having a hard time understanding why it works for certain write operations but never for read ops.

---

<div class="post-metadata">

**Author:** ![hpinhal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hpinhal/32/54944_2.png) [@hpinhal](https://discuss.elastic.co/u/hpinhal)\
**Post date:** [October 1, 2019, 4:26pm UTC](https://discuss.elastic.co/t/node-js-agent-not-instrumenting-mongoose/201254/4 "2019-10-01T16:26:55Z")

</div>

Turns out.... There's no support for mongodb 3.3 since it dropped support for mongodb-core.

> <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 22, 2019, 12:26pm UTC](https://discuss.elastic.co/t/node-js-agent-not-instrumenting-mongoose/201254/5 "2019-10-22T12:26:59Z")

</div>

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