Asynchronous Error capture in Sentry (Javascript)


#1

Recently I am working with Sentry to send exceptions to Server. I see that errors fron most of the immedate javascript execution statements are thrown to Window.onerror or else even If I wrap the code inside Raven.context(); the logs are sent to Server.

I have problem with callbacks; I see that this is not thrown in window.onerror at all (except in ajax errors). I cannot capture it even if it is inside Raven.context().

Ex: Raven.context(function(){
z=1; //throws error to window.onerror as well as logs to Sentry
RTBbg.checkLogin();
}

checkLogin: function(){
      chrome.tabs.create({url:myurl},function(tab){
             y=1; //error from here is not thrown to window.onerror or logged to Sentry even if it is under 
                    //Raven.context
       });
}

If I purposefuly wrap the above code
checkLogin: function(){
chrome.tabs.create({url:myurl},Raven.wrap(function(tab){
y=1; //error from here is not thrown to window.onerror but logged to Sentry

       }));
}

Is there any easy way of doing this.
I see already a discussion related to this which talks about limitation
https://github.com/getsentry/raven-js/issues/67

Do you have opinion on the below article. I see all errors are logged to console no matter synchrnous or asynchronous


#2

Can you give me a reproducible minimal example on GitHub to run? I’d be glad to investigate.


#3

My guess at what’s going on here is that Chrome’s tabs.create function is catching any exceptions thrown by the callback function that it accepts. This stackoverflow post seems to confirm that: https://stackoverflow.com/questions/40635838/chrome-js-api-handling-errors-inside-method-callbacks

Note that we do not claim to, and simply cannot, capture any thrown error - only those which are uncaught or otherwise explicitly captured, perhaps by some framework integrations, instrumentation of error handlers, or otherwise.

So either:

  1. we add some instrumentation for these chrome APIs - unclear what the scope of this is or the demand, seems somewhat niche
  2. users will need to Raven.wrap any callbacks passed to these API methods

#4

Thank you Lewis for your reply.