How do you get New Relic to log errors which crash the process using their New Relic application monitoring? The key things I'm trying to accomplish are to have errors which crash the process still get logged and some way to filter to these errors on the dashboard.
Here's my understanding so far:
New Relic transmits data to their cloud every minute. In the event a
uncaughtException
occurs, this will result in all of the data currently waiting to be transmitted to be lost.There is a
newrelic.noticeError()
which is supposed to take a second argument allowing you to pass custom parameters with an error. New relic gets the error, but not the custom parameters.
Simple Example:
var newrelic = require("newrelic");
var express = require("express");
var app = express();
app.get("/softFail/", function(req, res) {
res.send(500, "softFail");
});
app.get("/hardFail/", function(req, res) {
setImmediate(function() {
throw new Error("I failed");
});
});
app.listen(80);
process.on("uncaughtException", function(err) {
console.error("Uncaught Exception");
console.error(err.stack);
newrelic.addCustomParameter("crash", "true");
newrelic.noticeError(err);
console.log("sending errors to New Relic");
newrelic.agent.harvest(function() {
console.log("send complete, crashing process");
process.exit(1);
});
});
Using that block of code if I call /hardFail/ I'm able to get New Relic to at least log the error. Without the uncaughtException
handler I don't get anything to New Relic. The issue is that I can't differentiate between the errors which crash the process, and normal HTTP 500 errors.
Here's something things I've tried:
If I attempt to add
{ crash : true }
to thenoticeError
call it doesn't seem to have any affect.I've tried to do
domain
instead ofprocess.on
, that doesn't change the situation.If I attempt to alter the
name
of the error, such aserr.name = "CrashError"
then the error doesn't get transmitted at all.If I create a custom error type, and then new that, and copy the stack trace on to it, it still reports as type
Error
rather than theprototype.name
of my new error type.
harvest
, you helped me a lot! – Faizabadnode-newrelic
team: github.com/newrelic/node-newrelic/issues/1561 – Faizabad