artsy-newrelic
Advanced tools
Comparing version 1.2.0 to 1.3.0
36
index.js
if (!process.env.NEW_RELIC_LICENSE_KEY) { | ||
module.exports = (req, res, next) => { next() } | ||
module.exports = (req, res, next) => next() | ||
} else { | ||
@@ -8,2 +8,12 @@ process.env.NEW_RELIC_HOME = __dirname | ||
const reportAndCrash = err => { | ||
console.error(err.name, err.stack) | ||
newrelic.noticeError(err, { crash: true }) | ||
newrelic.shutdown({ collectPendingData: true }, err => { | ||
if (err) console.log('Failed to send to NewRelic.', err) | ||
else console.log('Sent to NewRelic, exiting process.') | ||
process.exit(1) | ||
}) | ||
} | ||
// Middleware to inject NewRelic browser monitoring and timeouts | ||
@@ -15,3 +25,14 @@ module.exports = (req, res, next) => { | ||
// Report uncaught exceptions with a custom | ||
// Report and crash when going over memory limit of the environment | ||
if (process.env.WEB_MEMORY && !process.env.NEW_RELIC_NO_MEMORY_LIMIT) { | ||
const interval = setInterval(() => { | ||
const MBUsed = process.memoryUsage().heapUsed / 1000000 | ||
if (MBUsed > Number(process.env.WEB_MEMORY)) { | ||
reportAndCrash(new Error('Memory limit exceeded')) | ||
clearInterval(interval) | ||
} | ||
}, Number(process.env.NEW_RELIC_MEMORY_CHECK_INTERVAL) || 60000) | ||
} | ||
// Report uncaught exceptions with a custom error | ||
const UncaughtError = function UncaughtError (err) { | ||
@@ -23,12 +44,3 @@ this.name = 'UncaughtError' | ||
UncaughtError.prototype = Error.prototype | ||
process.on('uncaughtException', (e) => { | ||
const err = new UncaughtError(e) | ||
console.error('Uncaught Exception', err.stack) | ||
newrelic.noticeError(err, { crash: true }) | ||
newrelic.shutdown({ collectPendingData: true }, (err) => { | ||
if (err) console.log('Failed to send to NewRelic.', err) | ||
else console.log('Sent to NewRelic, exiting process.') | ||
process.exit(1) | ||
}) | ||
}) | ||
process.on('uncaughtException', e => reportAndCrash(new UncaughtError(e))) | ||
} |
{ | ||
"name": "artsy-newrelic", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"description": "Plug-and-play NewRelic module wrapper configured for Artsy Node apps.", | ||
@@ -8,10 +8,12 @@ "main": "index.js", | ||
"connect-timeout": "^1.8.0", | ||
"newrelic": "^1.22.1" | ||
"newrelic": "^2.2.1" | ||
}, | ||
"devDependencies": { | ||
"jade": "^1.11.0", | ||
"blue-tape": "^1.0.0", | ||
"express": "^4.13.3", | ||
"jade": "^1.11.0", | ||
"prettier-standard": "^6.0.0", | ||
"rewire": "^2.5.2", | ||
"sinon": "^3.3.0", | ||
"standard": "^8.6.0", | ||
"rewire": "^2.5.2", | ||
"superagent": "^3.5.0", | ||
@@ -21,3 +23,5 @@ "tap-nyan": "^1.1.0" | ||
"scripts": { | ||
"test": "node test.js | tnyan", | ||
"test": "yarn test-server && yarn test-memory", | ||
"test-memory": "node test/memory.js | tnyan", | ||
"test-server": "node test/server.js | tnyan", | ||
"example": "foreman run node example/index.js" | ||
@@ -35,2 +39,2 @@ }, | ||
"homepage": "https://github.com/artsy/artsy-newrelic#readme" | ||
} | ||
} |
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 3 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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
100819
11
121
9
13
+ Added@newrelic/native-metrics@2.4.0(transitive)
+ Addedagent-base@1.0.2(transitive)
+ Addedasync@2.6.4(transitive)
+ Addedbuffer-from@1.1.2(transitive)
+ Addedconcat-stream@1.6.2(transitive)
+ Addedcore-util-is@1.0.3(transitive)
+ Addeddebug@2.6.9(transitive)
+ Addedextend@3.0.2(transitive)
+ Addedhttps-proxy-agent@0.3.6(transitive)
+ Addedisarray@1.0.0(transitive)
+ Addedjson-stringify-safe@5.0.1(transitive)
+ Addedlodash@4.17.21(transitive)
+ Addednan@2.22.0(transitive)
+ Addednewrelic@2.9.1(transitive)
+ Addedprocess-nextick-args@2.0.1(transitive)
+ Addedreadable-stream@2.3.8(transitive)
+ Addedsafe-buffer@5.1.2(transitive)
+ Addedsemver@5.7.2(transitive)
+ Addedstring_decoder@1.1.1(transitive)
+ Addedtypedarray@0.0.6(transitive)
+ Addedutil-deprecate@1.0.2(transitive)
- Removednewrelic@1.40.0(transitive)
Updatednewrelic@^2.2.1