-1

In my expressjs app, each time there is a request, a transaction will be recorded on New Relic. However, as each transaction comes from a different user, I want to add a custom attribute (userId) to the transaction so that I know from which user the request comes from.

The only way to show that custom attribute is from the transaction trace > transaction details.

However, it appears that ONLY long transactions have a trace. So, I can't track the userId for each transaction.

What's wrong am I doing? Is it a good practice to add custom attribute to each transaction?

Here is the important lines in my node.js code:

// beginning of the file
const newrelic = require('newrelic');

...

app.get('/blah', function(req, res, next) {
   newrelic.addCustomAttribute('test', 28);
   ...
});
JLavoie
  • 16,678
  • 8
  • 33
  • 39

1 Answers1

-1

For NodeJs that would be the best route. because of the way Node breaks out data (express, middleware, etc) the transactions can get a bit...weird.

What you can do (and I have done) is find specific transactions your concerned with (slow timing, etc) and instrument those out with the above code. Then add a newrelic.addCustomAttribute('ObjectName', Name);

to start calling the userId.

I believe "startWebTransaction" is the correct method to break out the functions call. But check the documents (goooooooogle) and you'll find examples.

Konoti
  • 1