Sentry and JQuery's .on


#1

I’m using Sentry for the Javascript frontend (require + Backbone) of a large project. I noticed that Raven doesn’t seem to pick up errors caused by callbacks. I’ve mostly experimented with .on, but chances are it affects our JQuery XHR calls and other things too. Here’s a JSFiddle that shows what’s going on:

https://jsfiddle.net/d1fj0vfL/13/

What’s the best way for me to get Raven to pick up errors that are the results of functions called by Jquery event callbacks? I’d really rather not go throughout my entire code base and surround every callback with Raven.context if I can help it.

Thanks!


#2

Hey @JoeDuncko, you have to call .install in order for global handlers to be attached.
You can verify that by adding this snipped at the top of your script tag and seeing console logs.

Raven.config('https://random@dsn.io/123', {
  dataCallback: function (data) {
    console.log(data)
    return data
  },
  shouldSendCallback: function () {
    return false
  }
}).install()

#3

Whoah, totally missed that! But that ended up not being my problem - while I neglected to run ‘.install()’ in my example, in my actual code base it was running.

Turns out that our issue was caused by us running jquery 1.12.4. You can see in the following example that when we have an ajax call that has errors in its callbacks, those errors aren’t caught by raven:

https://jsfiddle.net/bt1s76m9/30/

But when we run jquery 3.3.1 errors in ajax callbacks are caught just fine:

https://jsfiddle.net/bt1s76m9/32/

So that solves that!