How to use NewRelic’s instrumentation APIs in Node.js

New Relic provides instrumentation APIs for Node.js that allow you to customize the data that is collected and reported to the New Relic APM dashboard. Here’s how you can use these APIs:

  1. Install the newrelic package: You can install the newrelic package using npm:
   npm install newrelic
  1. Configure the agent: Before you can use the instrumentation APIs, you need to configure the New Relic agent. You can do this by creating a newrelic.js file in the root directory of your project and adding your New Relic license key:
   exports.config = {
     app_name: ['Your Application Name'],
     license_key: 'Your License Key',
     logging: {
       level: 'info'
     }
   };
  1. Use the instrumentation APIs: Once you have configured the New Relic agent, you can use the instrumentation APIs to customize the data that is collected and reported. Here are some examples:
  • Add custom attributes: You can add custom attributes to the transaction data using the addCustomAttribute() method: var newrelic = require('newrelic'); newrelic.addCustomAttribute('myCustomAttribute', 'myCustomValue');
  • Ignore transactions: You can ignore specific transactions using the ignoreTransaction() method: var newrelic = require('newrelic'); newrelic.ignoreTransaction();
  • Name transactions: You can name transactions using the setTransactionName() method: var newrelic = require('newrelic'); newrelic.setTransactionName('MyTransaction');
  • Create custom metrics: You can create custom metrics using the recordMetric() method: var newrelic = require('newrelic'); newrelic.recordMetric('MyCustomMetric', 1);
  • Use custom instrumentation: You can use custom instrumentation to monitor specific functions or methods using the wrapFunction() and wrapMethod() methods: var newrelic = require('newrelic'); var myFunction = function() { // ... }; newrelic.wrapFunction('MyFunction', myFunction);

These are just a few examples of the instrumentation APIs provided by New Relic for Node.js. You can find more information and examples in the New Relic documentation.

, , , ,

Related posts

Latest posts

Leave a Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

Please disable your adblocker or whitelist this site!

How to whitelist website on AdBlocker?

How to whitelist website on AdBlocker?

  1. 1 Click on the AdBlock Plus icon on the top right corner of your browser
  2. 2 Click on "Enabled on this site" from the AdBlock Plus option
  3. 3 Refresh the page and start browsing the site