Your data. Anywhere you go.

New Relic for iOS or Android


Download on the App Store    Android App on Google play


New Relic Insights App for iOS


Download on the App Store


Learn more

Close icon

Relic Solution: Adding Custom attributes to JavascriptError events:


#1

Adding user-defined attributes to JavascriptError events:

In this Level Up Solution, we will be adding custom attributes to JavascriptError events and querying the data in Insights.

What are the prerequisites for custom attributes?

In order for the Browser agent to send custom attributes to Insights, the following must be true:

  • The Browser agent script need to be inline in the head tag, before other script tags.
  • JavascriptError events require an Insights Pro subscription with your New Relic Browser subscription.

What are the parameters for custom attribute API call?

  • $error Required. Provide a meaningful error message that you can use when analyzing data on New Relic Browser’s JavaScript errors page.

  • $customAttributes Optional. An object containing name/value pairs representing custom attributes.


Example

Here is an example of how you might call the Browser API and send it to Insights. I defined a custom attribute and named it 'userName, I inserted the API call in the header tag as the call needs to be made before the window load event fires.

    <html>
    	<head>
    		<meta charset="UTF-8">
    			<title>Custom attributes to JavascriptError events</title>
    			<script type="text/javascript">window.NREUM||(NREUM={}),__nr_require=function(t,e,n){function r(n){if(!e[n]){var o=e[n]={exports:{}};t[n][0].call(o.exports,function(e){var o=t[n][1][e];return r(o||e)},o,o.exports)}return e[n].exports}if("function"==typeof __nr_require)return __nr_require;for(var o=0;o<n.length;o++)r(n[o]);return r}({1:[function(t,e,n){function r.......</script>
  				<script type="text/javascript">
    				newrelic.noticeError("this by JS New Relic", {"message":"apple", "second message":"oranges"});
    			</script>
		</head>
		<body>
    		Content of the document......
    	</body>
    </html>

Query Data with Insights*

The JavascriptError event is a default event that the Browser agent reports to Insights. You can add custom attributes to the JavascriptError event.

View All Errors with custom attributes

SELECT * FROM JavaScriptError  where message  IS NOT NULL

Counts of different types of messages

SELECT count(*) FROM JavaScriptError  facet `message`,`second message`  SINCE  30 minutes ago


Helpful Links