Browser: Unhandled promise rejection errors not showing on JS Errors page

  • Share what method you used to deploy Browser (APM or copy/paste):

copy/paste

  • Which version are you using? (Lite, Pro or SPA):

PRO+SPA

  • Please share your question/describe your issue below. Consider including any/all of the following:

I’m using the browser PRO+SPA version and I am reproducing steps in my application that cause unhandled promise rejections ie: http://2ality.com/2016/04/unhandled-rejections.html

However I am not seeing these errors in the NewRelic browser > JS Errors page

I have tried adding my own listener (via window.addEventListener("unhandledrejection ) to then call noticeError however it seems NewRelic is wrapping this listener, console logging the error but then doing nothing with the error after that.

Please can you advise on how to capture unhandled promise rejections so they appear in newrelic reports?

Thanks

Hi @r.lal - I think that the event listener you added requires changing. There is some sample script on this post, check the additional solutions as well, which could provide a method for you to use.

Hi @stefan_garnham

Thanks for your reply however the fact that New Relic does not report unhandled promise rejections automatically is odd.

Also it appears NR is wrapping any existing unhandledrejection errors and then not invoking the wrapped listener - so my listener never executes.

Please can you respond to the following, that New Relic browser:

a) does not support reporting of unhandled promise rejections
b) wraps any existing unhandledrejection handlers so the error is swallowed up and the wrapped listener is not invoked (this is what I have observed)
c) your recommendation is to implement my own listener which makes a direct request to log an error rather than via the noticeError API method.

Thanks

Hey @r.lal! I think you have a bit of a tough issue here that hasn’t been seen too frequently, hence the long response time on your question from the community :slight_smile: in doing research on my end, I’ve only seen the issue of unhandled promise rejections not being recorded brought up one other time. Let me pass on some of the info I found:

  • The Browser agent doesn’t record unhandled promise rejections automatically - this was true as of about 1.5 years ago and I haven’t been able to find anything that suggests that this behavior has changed. As I understand it, this was an intentional decision to ensure performance quality stays at maximum.
  • Errors are collected by wrapping Javascript functions - this includes the event listener you are adding, and is done to be able to collect information based on the stack trace. The agent doesn’t ever really swallow errors though; whenever the agent records an error, it handles it, records the error information, and then rethrows it.
  • The noticeError API call is the solution - Since we don’t collect unhandled promise rejections automatically, we do suggest using the API call.

One thing I also wanted to mention was your comment here:

I have tried adding my own listener (via window.addEventListener("unhandledrejection ) to then call noticeError however it seems NewRelic is wrapping this listener, console logging the error but then doing nothing with the error after that.

It’s interesting you mention that the agent is also logging the error to the console, this isn’t typical behavior that I’ve observed and doesn’t really make sense why we would be adding extra noise to the console for every error that’s recorded.

Could you try moving the noticeError API call directly into the logic for the promise, so that as soon as it’s determined that it’s rejected the API call is made? That way you won’t have to go the route of catching it after the fact with an event listener and instead record it at the same time it happens.

Let us know your results or if you have any questions!

1 Like