From a486bde329e365dc41f2ec6ac3a85da7fd3e873a Mon Sep 17 00:00:00 2001 From: Piotr Miazga Date: Wed, 17 Oct 2018 16:43:16 +0200 Subject: [PATCH] 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 --- resources/skins.minerva.scripts/errorLogging.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/resources/skins.minerva.scripts/errorLogging.js b/resources/skins.minerva.scripts/errorLogging.js index 8bbd90e99..a7b7ce9cf 100644 --- a/resources/skins.minerva.scripts/errorLogging.js +++ b/resources/skins.minerva.scripts/errorLogging.js @@ -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,