Your data. Anywhere you go.

New Relic for iOS or Android


Download on the App Store    Android App on Google play


New Relic Insights App for iOS


Download on the App Store


Learn more

Close icon

Custom attributes not logged when using MongoDB

transactions
mongodb

#1

Node Agent Question Template

  • What language agent version are you using? Any other relevant versions? (Node modules, etc.?)
    Node: v10.15.0
    Newrelic: 5.11.0
    Mongoose: 5.6.9

  • Describe what are you seeing? Describe how that differs from you were expecting to see?
    Hi, we are using newrelic in my company to trace transactions and various other staff. Among other things we add custom attributes in our transactions.

The problem that we are facing is that we are not able to see all the custom attributes that we were logging. After doing some investigation I noticed that the problem occurred when I was fetching data from MongoDB. Before fetching the data I have an active transaction, but after calling ‘findOne’ of mongodb the current transaction is null. See the bellow snippet:

require('newrelic').getTransaction()._transaction.trace.custom.attributes);
// transaction is active
const account: accounts.Document | null = await Accounts.findOne({ subdomain});
// transaction  is null here
require('newrelic').getTransaction()._transaction.trace.custom.attributes);

Because of the newrelic transaction being null, the custom attributes are lost.

The strange thing is that this only happens when I run my application in a staging environment or production. When I run this code from my computer custom attributes are logged successfully.

Do you have any idea what is going wrong?

Thanks in advance,
Kyriakos

Update: After some more digging, I found the following logs that seem related:

Determining query information for "findOne","component":"DatastoreShim","module":"mongodb","datastore":"MongoDB
Adding datastore instance attributes from obj.s.db + obj.s.topology","component":"DatastoreShim","module":"mongodb","datastore":"MongoDB
Found and parsed query MongoDB -> accounts/findOne","component":"DatastoreShim","module":"mongodb","datastore":"MongoDB
"Not recording function findOne, not in a transaction.","component":"DatastoreShim","module":"mongodb","datastore":"MongoDB
Determining query information for "next","component":"DatastoreShim","module":"mongodb","datastore":"MongoDB
Could not find datastore instance attributes.","component":"DatastoreShim","module":"mongodb","datastore":"MongoDB
Found and parsed query MongoDB -> accounts/next","component":"DatastoreShim","module":"mongodb","datastore":"MongoDB
Not recording function next, not in a transaction.","component":"DatastoreShim","module":"mongodb","datastore":"MongoDB
Not adding db instance metric attributes to segment "null","component":"DatastoreShim","module":"mongodb","datastore":"MongoDB
Determining query information for "findOne","component":"DatastoreShim","module":"mongodb","datastore":"MongoDB
Adding datastore instance attributes from obj.s.db + obj.s.topology","component":"DatastoreShim","module":"mongodb","datastore":"MongoDB
Found and parsed query MongoDB -> accounts/findOne","component":"DatastoreShim","module":"mongodb","datastore":"MongoDB
Not recording function findOne, not in a transaction.","component":"DatastoreShim","module":"mongodb","datastore":"MongoDB
Determining query information for "next","component":"DatastoreShim","module":"mongodb","datastore":"MongoDB
Could not find datastore instance attributes.","component":"DatastoreShim","module":"mongodb","datastore":"MongoDB
Found and parsed query MongoDB -> accounts/next","component":"DatastoreShim","module":"mongodb","datastore":"MongoDB
Not recording function next, not in a transaction.","component":"DatastoreShim","module":"mongodb","datastore":"MongoDB

#2

Thank you for all the info and I’m glad you’ve narrowed it down.

I think the reason why you are not seeing MongoDB queries in external services is that we have known issues with Mongoose causing Transaction state loss for MongoDB; a symptom of this is lack of data. Another symptom can be inaccurate data due to transaction conflation which throws numbers out of whack. In either case, these 2 issues come from Mongoose’s built-in connection pooling which largely affects our Node agent instrumentation, meaning our agent will not instrument parts of your application that it normally would.

We are aware that most of our Node community use MongoDB with Mongoose and that we need to support Mongoose out of the box. We are really making an effort to push this current Feature Request forward as we have a lot of clients expressing this need.

As a potential workaround, we’d suggest trying out some custom instrumentation. Another possibility would be removing mongoose and just using MongoDB and see if there is a difference in the data reported.

Please visit our Explorers Hub existing Feature Idea for this to vote on it.

I hope this helps in your planning,
Michael