Hygiene: Track minerva errors count only once

To minimize the traffic sent to the stats endpoint we should
track errors only once after request is done, not on every
error occurence.

Bug: T212970
Change-Id: I64f101159aa1f2179e612effa850851fffcf39c6
This commit is contained in:
Piotr Miazga 2018-10-17 16:43:16 +02:00 committed by Pmiazga
parent e1c3fb68e4
commit a486bde329
1 changed files with 13 additions and 3 deletions

View File

@ -1,5 +1,10 @@
( function ( M, requestIdleCallback, track, config, trackSubscribe, user, experiments ) {
requestIdleCallback( function () {
/**
* Errors count in the current pageview
* @type {number}
*/
var errorsCount = 0;
/**
* Handle an error and log it if necessary
* @param {string} errorMessage to be logged
@ -30,7 +35,7 @@
isAnon: user.isAnon(),
revision: page.getRevisionId()
};
errorsCount++;
if ( isErrorLoggingEnabled ) {
track( EVENT_CLIENT_ERROR_LOG,
util.extend( {
@ -45,8 +50,10 @@
}, DEFAULT_ERROR_DATA )
);
}
if ( config.get( 'wgMinervaCountErrors' ) ) {
mw.track( 'counter.MediaWiki.minerva.WebClientError', 1 );
}
function logErrorsCount() {
if ( errorsCount > 0 ) {
mw.track( 'counter.MediaWiki.minerva.WebClientError', errorsCount );
}
}
// track RL exceptions
@ -58,6 +65,9 @@
trackSubscribe( 'global.error', function ( topic, error ) {
handleError( error.errorMessage, error.lineNumber, error.columnNumber, error.url );
} );
if ( config.get( 'wgMinervaCountErrors' ) ) {
$( window ).on( 'beforeunload', logErrorsCount );
}
} );
}(
mw.mobileFrontend,