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

Feature Idea: Can I query javascript errors on new relic insights?

insights
feature-idea

#22

Hi!
Has that been resolved?
Thanks!


#23

@mauro_luna We have not announced this feature being added as of yet. I see you started the feature request so you will be notified if is it added! I am also letting the product managers know of your continued interest.


#24

+1 - please add my name to the request


#25

Hey!

I’ve added you to this Feature request!


#26

Please add my name to this request


#27

Happy to, @martha_negron! Adding a feature request for you now! :thumbsup:


#28

+1 - please add my name to the request.

Thanks!!


#29

You got it, @leandro.romero! Adding your input to a feature request right now! :thumbsup:


#30

Is this in the works yet?

+1 and please add my name to this request too.


#31

Hi @dmhart unfortunately I don’t have any hard information on whether the feature is in the works myself, it’s also worth bearing in mind that while we take feature request seriously and our product managers review every one when plotting our roadmap, it’s not a guarantee the feature would be implemented. It ensures the idea is put on the table and discussed though.

I have however filed a feature request on your behalf, which in the event the feature was chosen for development attention, will mean that you would be notified by email if it’s rolled out to product, as I’ve tagged your customer details to this feature request.


#32

Hello! please vote if you want to obtain js errors in insights!


#33

I gave this a +1. I would also like to add that it would be super helpful if we could get the JS error ID as part of the Insights data returned in order to drill into the error details on the Browser JS Errors dashboard (unless you can provide the same graphs on the Insights dashboard).


#34

Thanks so much for providing more detail @eric3. Those details are really important to our engineering teams.


#35

For those that would like a workaround solution until the feature is applied, you can use this as an example to create a custom event within Insights which you can then query on for dashboards or alerts.

You will need your Insights API key and the account id where the event will be stored.

I am using JQuery here to make the API call but you could replace the $ajax with your own implementation using XMLHttpRequest if you want to reduce 3rd party dependencies.

Disclaimer:
I have not tested this sample so you should verify prior to implementing in a live environment!

New Relic may change their object naming conventions so reference to newrelic.info.applicationID may not work in future implementations of the Browser injected script!

newrelic.setErrorHandler(function (err) {

        var stack = e.error.stack; 
        var message = e.error.toString(); 
        var pageURL = window.location.href;

        $.ajax({ 
            method: 'POST', 
            url: 'https://insights-collector.newrelic.com/v1/accounts/[Your Account Id]/events', 
            headers: { 'X-Insert-Key': '[Your Insights API Key]' }, 
            data: { 
                "eventType":"JavascriptError", 
                "appId": newrelic.info.applicationID, 
                "message":message, 
                "stack":stack, 
                "pageUrl":pageURL
            } 
        }); 

     return false;
   }
})

Filter JS errors by URL
Can we use NRQL to find JS Errors?
Session Traces for Specific Errors
Dec. 9, 2016 Post of the Week—Insights, Workarounds and Feature Ideas
Session trace and external JS asset that fails to load
Record complete URL in JS Error
Browser: Unhandled promise rejection errors not showing on JS Errors page
#36

If anyone has implemented this workaround, please do feedback on if it worked or any changes that are required.


#37

I’m also interested in this feature.


#38

Similar to stefan_garnham’s work around, I came up with the following solution which lets you then run a query similar to the following SELECT * FROM PageAction where actionName = 'JSError'

newrelic.setErrorHandler(function(error) {
    newrelic.addPageAction('JSError', {
        message: error.message,
        errorName: error.name,
        errorStackTrace: error.stack,
        url: window.location.toString(),
        otherField: someOtherValueYouMayWantHere
      });
});

#39

I ended up using PageActions to log these errors separately and create an insights dashboard. Note that stefan_garnham’s method didn’t work (I ran into CORS issues), but addPageAction does it!

const data = {
  'api.endpointAnonymized' : getEndpointAnonymized(error),
  'api.httpStatus'         : getFromApi(error, 'httpStatus'),
  'api.method'             : getFromApi(error, 'method'),
  'api.url'                : getFromApi(error, 'url'),
  message                  : error.message,
  'page.url'               : error.page.url,
  'redux.actionType'       : getActionType(error, elementToTrackTo),
  type                     : error.type,
  'user.id'                : error.user.id,
  'user.role'              : error.user.role,
};

/*
  new relic insights can only facet by one field, so we have to create some to get meaningful data
  these are named "facets" just to denote that they're explicitly used for this one aspect of filtering
*/
data['facets.api.basicData']      = getApiBasicData(error, data);
data['facets.user.idAndRole']     = `${data['user.id']}-${data['user.role']}`;
data['facets.page.urlAnonymized'] = anonymizeUrl(error.page.url);

// https://docs.newrelic.com/docs/browser/new-relic-browser/browser-agent-spa-api/add-page-action
window.newrelic.addPageAction('Client Error', data);


August 18, 2017 Post of the Week—Insights, AMP and Alerts
#40

Love it @averyvery - this is an excellent workaround. Really appreciate you sharing.


#41

We’re also interested in having JS errors available in Insights