Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/* global Sentry */
// By setting the values on meta tags, we can load the raven library
// between the vendor libraries without having to split them into separate
// javascript bundles
(function($) {
'use strict';
var userId,
organization,
hosts,
dsn,
config = { debug: true };
function getMetaValue(name, fallback) {
var value = $('meta[name=' + name + ']').attr('content');
if (value) {
return value;
} else {
return fallback;
}
}
function hostsToWhitelistURLs(hosts) {
var urls = [],
i,
len = hosts.length;
for (i = 0; i < len; i = i + 1) {
urls.push(new RegExp(hosts[i], 'i'));
}
return urls;
}
userId = getMetaValue('raven-user-id');
organization = getMetaValue('raven-organization');
hosts = getMetaValue('raven-hosts');
dsn = getMetaValue('raven-dsn');
if (!dsn) {
console.info('Sentry DSN not provided. Error logging disabled.');
return;
} else {
config.dsn = dsn;
}
if (hosts) {
config.whitelistUrls = hostsToWhitelistURLs(JSON.parse(hosts));
}
/* ignore, once and for all, these errors.. */
config.beforeSend = function(event, hint) {
var error = hint.originalException;
// dispense with it if it's not an exception
if (!error || !error.message) {
return event;
}
// start filtering. i wish i could build a switch, but it's fugly.
if (error.message.match(/execute code from a freed script/i)) {
return null;
} else if (error.message.match(/un script liberado/i)) {
return null;
} else {
return event;
}
};
/* Ignore common errors that seemingly have no impact on the user */
// config.ignoreErrors = [/execute code from a freed script/, /un script liberado/];
/*
Do not report on unhandled promise rejections
https://docs.sentry.io/clients/javascript/usage/#raven-js-promises
*/
config.captureUnhandledRejections = false;
Sentry.init(config);
if (userId) {
Sentry.setUser({ id: userId, organization: organization });
}
$(document).ajaxError(function() {
if (arguments[1].status >= 500) {
Sentry.withScope(function(scope) {
scope.setExtra('arguments', arguments);
scope.setTag('source', 'ajax');
Sentry.captureMessage('AJAX Request Failure');
});
}
});
})(window.jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.