Skip to content

senecajs/seneca-telemetry-newrelic

Repository files navigation

Seneca telemetry-newrelic

Seneca telemetry-newrelic is a plugin for Seneca

Capture NewRelic telemetry for Seneca actions.

npm version

build

Coverage Status

Known Vulnerabilities

DeepScan grade

Maintainability

| Voxgig | This open source module is sponsored and supported by Voxgig. |

|---|---|

Description

This is a plugin for integrating Newrelic with Seneca.js

Dependencies

  • Install Newrelic infrastructure agent

Booting

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,

	},

});

Events

Send your own custom event data.

Events API should be used to track specific/edge cases, in most of cases, try to use Metrics.

Usage

// The base pattern is: "plugin:newrelic,api:event"

// All res objects follow the same pattern: { err?: Error, statusCode?: number, body?;

// You can fulfill the attributes object, and then use it inside Newrelic to query and aggregate your data.

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)

});

Metrics

Send your your own custom dimensional metrics to Newrelic.

The SDK currently supports three types of Metrics: count, gauge, summary. You can read about metrics types here.

Usage

// 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) => {

// err is null

// handle res here (Check for errors, log data, et cetera)

})

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');

Tracing

After enabling it, Seneca will start sending distributed tracing data to Newrelic.

In the context of Seneca, in your application when a action is dispatched, Seneca will trace it down until it finishes/arrives, then you send this distributed aggregated data to Newrelic.

In the Newrelic UI you will be able to see the performance of your seneca actions.

Segment

TODO