-
Notifications
You must be signed in to change notification settings - Fork 11
/
newrelicHelper.js
43 lines (36 loc) · 1017 Bytes
/
newrelicHelper.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
let newrelic = {};
const excludedEnvs = ['dev', 'test'];
/**
* If the newrelic module was included will invoke
* the given method eventually applying params
*
* @param {String} methodName
* @return {*}
*/
function callMethod(methodName) {
if (newrelic[methodName]) {
const args = [].splice.call(arguments, 1, (arguments.length - 1));
return newrelic[methodName].apply(newrelic, args);
}
}
const nmNewRelic = {
getBrowserTimingHeader: function() {
return callMethod('getBrowserTimingHeader');
},
setTransactionName: function(name) {
callMethod('setTransactionName', name);
},
noticeError: function(error, options = {}) {
options = options || {};
if (options.transactionName) {
nmNewRelic.setTransactionName(options.transactionName);
}
callMethod('noticeError', error, options);
}
};
module.exports = function(env) {
if (!Object.keys(newrelic).length && !excludedEnvs.includes(env)) {
newrelic = require('newrelic');
}
return nmNewRelic;
};