Merge "Client side error reporting for Minerva+MobileFrontend"

This commit is contained in:
jenkins-bot 2018-08-30 22:40:19 +00:00 committed by Gerrit Code Review
commit 34ead3f8c5
4 changed files with 78 additions and 1 deletions

View file

@ -36,6 +36,17 @@ for the page.
Controls whether site notices should be shown.
See <https://www.mediawiki.org/wiki/Manual:$wgSiteNotice>.
#### $wgMinervaErrorLogSamplingRate
* Type: `Integer`
* Default: `0`
Whether to log client side errors to EventLogging. If 0, error logging is disabled.
If 0.5, 50% of all client side errors will be logged to the EventLogging client.
If 1, all errors will be logged to the EventLogging client, thus when enabling this
care should be taken that your setup is bug free in order to not overwhelm the EventLogging
server.
#### $wgMinervaApplyKnownTemplateHacks
* Type: `Boolean`

View file

@ -190,7 +190,11 @@ class MinervaHooks {
* @return bool
*/
public static function onResourceLoaderGetConfigVars( &$vars ) {
$config = MediaWikiServices::getInstance()->getConfigFactory()
->makeConfig( 'minerva' );
$vars += [
'wgMinervaErrorLogSamplingRate' => $config->get( 'MinervaErrorLogSamplingRate' ),
'wgMinervaReadOnly' => wfReadOnly()
];

View file

@ -0,0 +1,59 @@
( function ( M, requestIdleCallback, track, config, trackSubscribe, user, experiments ) {
requestIdleCallback( function () {
/**
* Handle an error and log it if necessary
* @param {string} errorMessage to be logged
* @param {number} [lineNumber] of error
* @param {number} [columnNumber] of error
* @param {string} [errorUrl] to be logged
*/
function handleError( errorMessage, lineNumber, columnNumber, errorUrl ) {
var errorSamplingRate = config.get( 'wgMinervaErrorLogSamplingRate', 0 ),
sessionToken = user.sessionId(),
EVENT_CLIENT_ERROR_LOG = 'wikimedia.event.WebClientError',
page = M.getCurrentPage(),
util = M.require( 'mobile.startup/util' ),
errorExperiment = {
name: 'WebClientError',
enabled: errorSamplingRate > 0,
buckets: {
on: errorSamplingRate,
off: 1 - errorSamplingRate
}
},
isErrorLoggingEnabled = experiments.getBucket( errorExperiment, sessionToken ) === 'on',
DEFAULT_ERROR_DATA = {
sessionToken: sessionToken,
skin: config.get( 'skin' ),
wgVersion: config.get( 'wgVersion' ),
mobileMode: config.get( 'wgMFMode', 'desktop' ),
isAnon: user.isAnon(),
revision: page.getRevisionId()
};
if ( isErrorLoggingEnabled ) {
track( EVENT_CLIENT_ERROR_LOG,
util.extend( {
userUrl: window.location.href,
errorUrl: errorUrl,
errorMessage: errorMessage,
// Due to concerns for the length of the stack trace and going over the limit for URI length
// this is currently set to empty string.
errorStackTrace: '',
errorLineNumber: lineNumber || 0,
errorColumnNumber: columnNumber || 0
}, DEFAULT_ERROR_DATA )
);
}
}
// track RL exceptions
trackSubscribe( 'resourceloader.exception', function ( topic, data ) {
var err = data.exception;
handleError( err.message, err.lineNumber, err.columnNumber );
} );
// setup the global error handler
trackSubscribe( 'global.error', function ( topic, error ) {
handleError( error.errorMessage, error.lineNumber, error.columnNumber, error.url );
} );
} );
}( mw.mobileFrontend, mw.requestIdleCallback, mw.track, mw.config, mw.trackSubscribe, mw.user, mw.experiments ) );

View file

@ -22,6 +22,7 @@
}
},
"config": {
"MinervaErrorLogSamplingRate": 0,
"MinervaDownloadNamespaces": [ 0 ],
"MinervaEnableSiteNotice": false,
"MinervaCustomLogos": [],
@ -152,7 +153,8 @@
}
},
"EventLoggingSchemas": {
"PageIssues": 18326688
"PageIssues": 18326688,
"WebClientError": 18340282
},
"ResourceModules": {
"skins.minerva.base.reset": {
@ -430,6 +432,7 @@
"resources/skins.minerva.scripts/PageIssuesOverlay.js",
"resources/skins.minerva.scripts/pageIssues.js",
"resources/skins.minerva.scripts/init.js",
"resources/skins.minerva.scripts/errorLogging.js",
"resources/skins.minerva.scripts/initLogging.js",
"resources/skins.minerva.scripts/mobileRedirect.js",
"resources/skins.minerva.scripts/search.js",