A Seneca.js plugin
![]() |
This open source module is sponsored and supported by Voxgig. |
|---|
Capture NewRelic telemetry for Seneca actions.
npm install @seneca/telemetry-newrelicDependencies:
- Install Newrelic infrastructure agent
const Seneca = require('seneca');
const newrelicPlugin = require('seneca-telemetry-newrelic');
const SECRET_NEWRELIC_API_KEY = "SECRET_NEWRELIC_API_KEY";
const MY_SERVICE_NAME = "MY_SERVICE_NAME";
const senecaInstance = Seneca()
.use('promisify')
.use(newrelicPlugin, {
// Enable Tracing
tracing: {
enabled: true,
accountApiKey: SECRET_NEWRELIC_API_KEY,
serviceName: MY_SERVICE_NAME,
},
// Enable Segments
segment: {
enabled: true,
},
// Enable Metrics
metrics: {
enabled: true,
accountApiKey: SECRET_NEWRELIC_API_KEY,
},
// Enable Events
events: {
enabled: true,
accountApiKey: SECRET_NEWRELIC_API_KEY,
},
});See test/ for more usage examples.
Plugin for integrating New Relic with Seneca.js for telemetry and observability.
If you're using this module and need help, you can:
- Post a github issue
- Tweet to @senecajs
- Ask on the Gitter
Send your own custom event data.
Events API should be used to track specific/edge cases. In most cases, try to use Metrics.
// The base pattern is: "plugin:newrelic,api:event"
// All res objects follow the same pattern: { err?: Error, statusCode?: number, body? }
seneca.act('plugin:newrelic,api:event,somethingHappened,attributes:{isOK:false,error:"System Crash - CODE 784"}', (err, res) => {
// err is null
// handle res here (Check for errors, log data, et cetera)
});Send your own custom dimensional metrics to New Relic.
The SDK supports three types of Metrics: count, gauge, summary. Read about metric types here.
// The base pattern is: "plugin:newrelic,api:metric"
// You can also pass a custom object in the attributes field
// All res objects follow the same pattern: { err?: Error, statusCode?: number, body? }Gauge example:
// value must be typeof number
seneca.act("plugin:newrelic,api:metric,type:gauge,value:2,name:custom.seneca.counter,attributes:{'user.name': 'Vitor', age: 26}", (err, res) => {
// handle res here
})Summary example:
// value must be of typeof { count?: number, sum?: number, min?: number, max?: number }
seneca.act('plugin:newrelic,api:metric,type:summary,name:sumOfSomething,value:{sum: 1}');Count example:
// value must be typeof number
seneca.act('plugin:newrelic,api:metric,type:count,name:custom.counter,value:10');After enabling it, Seneca will start sending distributed tracing data to New Relic.
When an action is dispatched, Seneca traces it until it finishes, then sends the aggregated data to New Relic. In the New Relic UI you will see the performance of your Seneca actions.
TODO
The Senecajs org encourages open participation. If you feel you can help in any way, be it with documentation, examples, extra testing, or new features please get in touch.
npm run testIntegrates with New Relic for observability of Seneca microservices.

