spm-metrics-js
Advanced tools
Comparing version 1.0.7 to 1.0.9
@@ -18,3 +18,7 @@ 'use strict' | ||
function SpmCustomMetrics (token, metricsInterval, metricsApiEndpoint) { | ||
this.metricsUrl = (metricsApiEndpoint || 'https://spm-receiver.sematext.com/receiver/custom/receive.json?token=') + token | ||
if(process.env.SPM_URL) { | ||
this.metricsUrl = process.env.SPM_URL.replace('_bulk', 'receiver/custom/receive.json?token=' + token) | ||
} else { | ||
this.metricsUrl = (metricsApiEndpoint || 'https://spm-receiver.sematext.com/receiver/custom/receive.json?token=') + token | ||
} | ||
this.token = token || process.env.SPM_TOKEN | ||
@@ -84,6 +88,8 @@ this.datapoints = [] | ||
if (err) { | ||
self.emit('error', err) | ||
self.emit('send error', err) | ||
} else { | ||
self.emit('send metrics', { res: res, source: 'send' }) | ||
} | ||
}).on('error', function (err) { | ||
self.emit('send error', err) | ||
}) | ||
@@ -103,3 +109,3 @@ } | ||
var options = { | ||
url: 'https://event-receiver.sematext.com/' + this.token + '/' + type, | ||
url: (process.env.SPM_EVENTS_URL || 'https://event-receiver.sematext.com') + '/' + this.token + '/' + type, | ||
headers: { | ||
@@ -114,13 +120,12 @@ 'User-Agent': 'spm-metrics-js', | ||
this.events = [] | ||
var self = this | ||
request.post(options, function (err, res) { | ||
if (err) { | ||
self.emit('error', { err: err, source: 'sendEvent'}) | ||
} else { | ||
self.emit('send event', { source: 'sendEvent', event: event, err: err }) | ||
} | ||
if (callback) { | ||
callback(err, res) | ||
} | ||
}) | ||
request.post(options, function (err, res) { | ||
if (callback) { | ||
return callback(err, res) | ||
} | ||
if (err) { | ||
self.emit('send error', { err: err, source: 'sendEvent'}) | ||
} else { | ||
self.emit('send event', { source: 'sendEvent', event: event, err: err }) | ||
} | ||
}) | ||
} | ||
@@ -127,0 +132,0 @@ |
{ | ||
"name": "spm-metrics-js", | ||
"version": "1.0.7", | ||
"version": "1.0.9", | ||
"description": "Node.js client for SPM - Custom Metrics and Event API", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
var SPM = require('../lib/index.js') | ||
var token = process.env.SPM_TOKEN | ||
var trace = require ('trace') | ||
// var trace = require ('trace') | ||
describe('spm custom metrics ', function () { | ||
@@ -12,3 +12,3 @@ it('set metric', function (done) { | ||
}) | ||
spmcm.once('error', done) | ||
spmcm.once('send error', done) | ||
var testMetric = spmcm.getCustomMetric({ name: 'test.metric', aggregation: 'avg', filter1: 'filter1', filter2: 'filter2' }) | ||
@@ -39,3 +39,3 @@ testMetric.set(42) | ||
} else { | ||
done() | ||
done(err) | ||
} | ||
@@ -59,3 +59,2 @@ }) | ||
}) | ||
spmcm.once('error', done) | ||
var testMetric = spmcm.getCustomMetric({ name: 'timer', aggregation: 'avg', filter1: 'filter1', filter2: 'filter2' }) | ||
@@ -90,3 +89,3 @@ var stopwatch = testMetric.timer().start() | ||
spmcm.send() | ||
spmcm.once('error', done) | ||
spmcm.once('send error', done) | ||
} catch (err) { | ||
@@ -93,0 +92,0 @@ done(err) |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
33936
10
459
6