mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/MinervaNeue
synced 2024-11-28 16:10:55 +00:00
cd528e120b
This adds a client side error logger that will store errors in EventLogging. We will use it to get a sense of the number of errors inside mobile. To enable make use of the new configuration variable wgMinervaErrorLogSamplingRate = 1 Notes: * the optional `meta` field will not be utilised by the generic error handler. * URI length is not trimmed for title. We will consider whether we need to make any adjustments to the schema values during roll out. ** For stack trace, we limit the length by removing errorUrl (which is logged separately) Testing: Add throw new Error('asasasa'); anywhere in your code and make sure the code executes. It should trigger an Error event provided that configuration has been updated. Bug: T202026 Change-Id: I07f01b4c025b2e5e4cbf88ec05e7c536442c62cc
60 lines
2.2 KiB
JavaScript
60 lines
2.2 KiB
JavaScript
( 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 ) );
|