Throttle Sentry exceptions

This commit is contained in:
Gregory Schier 2016-10-28 11:42:40 -07:00
parent 35c19ed305
commit b9fd0a03b0
2 changed files with 32 additions and 17 deletions

View File

@ -45,7 +45,6 @@ export async function findResourcesForResourceGroup (resourceGroupId) {
}
export async function getResourceById (id) {
// TODO: this query should probably include resourceGroupId as well
const rawDocs = await _promisifyCallback(_getDB(TYPE_RESOURCE), 'find', {id});
return rawDocs.length >= 1 ? rawDocs[0] : null;
}

View File

@ -12,7 +12,6 @@
<script src="./external/raven.min.js"></script>
<script>
// UPDATE HANDLERS
(function () {
const CHECK_FOR_UPDATES_INTERVAL = 1000 * 60 * 60 * 3; // 3 hours
@ -36,9 +35,18 @@
})();
</script>
<script>
// Sentry
// Sentry (with rate limiting)
(function () {
// Send a maximum of n errors per interval
const MAX_ERRORS_PER_INTERVAL = 5;
const MAX_ERRORS_INTERVAL = 1000 * 60;
// Variable to keep track of errors per interval
let intervalErrorCount = 0;
// Reset error count after every interval
setInterval(() => intervalErrorCount = 0, MAX_ERRORS_INTERVAL);
if (process.env.INSOMNIA_ENV !== 'development') {
Raven.config('https://786e43ae199c4757a9ea4a48a9abd17d@sentry.io/109702', {
logger: 'electron.renderer',
environment: process.env.INSOMNIA_ENV || 'production',
@ -50,6 +58,18 @@
includePaths: [
/^(?!.*raven.min.js$).*$/ // Ignore raven stuff
],
shouldSendCallback: function (data) {
if (process.env.INSOMNIA_ENV === 'development') {
return false;
}
if (intervalErrorCount++ > MAX_ERRORS_PER_INTERVAL) {
console.log('-- Throttling Sentry Exceptions --');
return false;
}
return true;
},
dataCallback: function (data) {
var normalize = function (filename) {
var match = filename.match(/\/(app.asar|build)\/(.*)/);
@ -72,23 +92,20 @@
return data
}
}).install();
console.log('-- Initialized Sentry --');
} else {
console.log('-- Did not Initialize Sentry --');
}
})();
</script>
<script>
const {productName, version} = require('./package.json');
if (process.env.INSOMNIA_ENV === 'development') {
document.title = `${productName} v${version} (DEV)`;
} else {
document.title = `${productName} v${version}`;
}
(function () {
const {productName, version} = require('./package.json');
if (process.env.INSOMNIA_ENV === 'development') {
document.title = `${productName} v${version} (DEV)`;
} else {
document.title = `${productName} v${version}`;
}
})()
</script>
<script>
// HOT RELOADING IN DEV
(function () {
const script = document.createElement('script');
script.src = (process.env.HOT) ? 'http://localhost:3333/build/bundle.js' : './bundle.js';
@ -98,7 +115,6 @@
<script>
// SOME HELPERS
document.body.setAttribute('data-platform', process.platform);
</script>
</body>