mediawiki-skins-MinervaNeue/resources/skins.minerva.scripts/errorLogging.js
jdlrobson 6b8f8568a1 Restrict the number of errors we log in a given session
One IP address, logged 3,029 errors across 2 pages
This is not helpful as it makes the error seem more widespread
than it really is so let's not logged errors after the first 5.

Change-Id: I8abfc3c3852827ab84a06740356e9b9f659a2d03
2020-07-17 19:05:25 +00:00

45 lines
1.7 KiB
JavaScript

( function ( track, config, trackSubscribe, user ) {
module.exports = function () {
var suffix = user.isAnon() ? '.anon' : '.loggedin',
// we will keep track of errors counted, so that we don't overcount problematic
// browsers/users which are generating multiple issues. See MAX_ERRORS.
reportedInThisSession = 0,
// Very conservative for now.
// After this many errors are tracked, no more will be logged.
MAX_ERRORS = 5,
COUNTER_NAME = 'counter.MediaWiki.minerva.WebClientError' + suffix;
/**
* Count javascript errors, except for those associated with localStorage
* being full or unavailable.
*
* @param {string} topic name of the event being tracked
* @param {Object} data event payload
*/
function countError( topic, data ) {
var isLocalStorage = data && data.source === 'store-localstorage-update';
// Some errors, for example the Leaflet "Set map center and zoom first"
// error (T257872) can trigger a high volume of client side error reports to the server.
// At time of writing 1 IP logged 245 errors in the same session and page and another
// logged 3,029 errors across 2 pages. To filter these kind of errors out, set a cap
// on the amount of errors that can be logged in a single session.
if ( !isLocalStorage && reportedInThisSession < MAX_ERRORS ) {
track( COUNTER_NAME, 1 );
}
reportedInThisSession++;
}
if ( config.get( 'wgMinervaCountErrors' ) ) {
// track RL exceptions
trackSubscribe( 'resourceloader.exception', countError );
// setup the global error handler
trackSubscribe( 'global.error', countError );
}
};
}(
mw.track,
mw.config,
mw.trackSubscribe,
mw.user
) );