This example application shows you how to use the newrelic.instrument and shim.record API. This API allows you to instrument virtually any module that New Relic does not already support. In this example, we will instrument a simple module, a rudimentary job queue (jobQueue
) that schedules and runs a series of basic jobs.
- Clone or fork this repository.
- Navigate to this example's sub directory
cd newrelic-node-examples/custom-instrumentation/instrument
- Install dependencies and run application.
npm install cp env.sample .env # Fill out `NEW_RELIC_LICENSE_KEY` in .env and save # Start the application npm start
- The app will automatically start adding example jobs to a queue and run them. You should see the following in the console when the instrumentation takes place.
[NEWRELIC] instrumenting 'job-queue' Callback job done Promise job done
-
After a few minutes, you should be able to see
job-queue
instrumented in New Relic. From the dashboard, navigate to 'APM & Services' and then select the 'Example Job Queue App' entity. -
Then select 'Distributed tracing'. You should see the trace groups
firstTransacation
,secondTransaction
, andthirdTransaction
. Inside these groups will be our custom instrumentation. Select any trace group and then select a single trace. -
Under
firstTransaction
orsecondTransaction
, toggle 'Show in-process spans' and you will see 'scheduleJob - job'; this shows the name of which job was recorded. UnderthirdTransaction
, you will seequeue.runJobs
instrumented as 'runJobs'.
This application consists of the following files:
index.js
: a simple app that utilizes our example modulejob-queue.js
: an example module that provides a queue class that you can use to run and schedule jobsinstrumentation.js
: all of the New Relic instrumentation is in here; thenpm start
command makes sure this module is loaded firstnewrelic.js
: a basic, sample New Relic configurartion