Important
To use this API, you need either a Browser Pro or Pro+SPA edition of the browser agent.
Syntax
newrelic.noticeError(error object $error, [object $customAttributes])
Identifies a browser error without disrupting your app's operations.
Requirements
Custom attributes argument requires agent version nr-1118 or higher.
newrelic.noticeError()
requires agent version nr-499 or higher.
NREUM.noticeError()
requires agent version nr-411 or higher.
Browser monitoring must be enabled.
JavaScript error monitoring must be enabled.
Description
Use this call to notice or log your app's handled or other miscellaneous errors. This is useful when you have caught and handled an error, but you still want to identify it without disrupting your app's operation.
You can also use the API to notice errors that otherwise would be reported without any detail, such as errors that happen during the script initialization or in an inline event handler. The errors will appear in the JavaScript errors page along with other errors New Relic normally detects. They will also be recorded as a JavaScriptError
event. For example:
var err = new Error('Report caught error to New Relic');newrelic.noticeError(err);
Note: If more than 1000 JavaScriptError
events is sent in a single request, only 1000 separate events is recorded. However, total number of events is preseved internally and accessible by using EXTRAPOLATE
query clause.
Parameters
Parameter | Description |
---|---|
error object | Required. Provide a meaningful error message that you can use when analyzing data on browser's JavaScript errors page. |
| Optional. An object containing name/value pairs representing custom attributes. |
Examples
Non-critical errors
This example shows how to use the newrelic.noticeError
API to report caught errors that you do not want to disrupt your application. This is useful when non-critical errors do not have an impact on the user's experience, but you still want to report them to the developer. The example code safely uses a default foo
object in case of bad JSON.
var foo;try { foo = JSON.parse('{ "bar"');} catch (err) { //Report caught error to New Relic newrelic.noticeError(err);
foo = { bar: 'default value' };}alert(foo.bar);
Callback with optional error
This example shows how to report an error to New Relic when using the error and response pattern callbacks popularized by Node.js and common in Browserify development. You can replace alert(body);
with your own relevant message.
var xhr = require('xhr');xhr('http://localhost:8080', function(err, resp, body) { //Report unthrown error to New Relic if (err) return newrelic.noticeError(err); //Handle successful response alert(body);});
Promise-based API example
Promises provide a single pattern for handling asynchronous interactions, making it easy to handle asynchronous errors. However, this also makes it easy to ignore errors completely, leaving applications broken in ways that developers cannot see. This example reports those asynchronous errors to New Relic to prevent them from being overlooked.
var rest = require('rest');rest('/').then(function(res) { //Handle successful response alert(res.entity);}, function(err) { //Report unthrown error to New Relic newrelic.noticeError(err);});
Capturing custom attributes example
try { // code that throws an error} catch (err) { newrelic.noticeError(err, { attribute1: 'value1', attribute2: 2 });}
Browser limitations (Apple Safari and Microsoft Internet Explorer only)
If an error is not thrown, it will not have a stack trace. If you want the newrelic.noticeError
API to report a stack trace with all browser types, you must manually throw and then catch the error before you pass it to the API.
try { throw errorObject;} catch (err) { newrelic.noticeError(err);}