jenkins-bot has submitted this change and it was merged. Change subject: Add PHP error logging to Sentry extension ......................................................................
Add PHP error logging to Sentry extension Bug: T85188 Change-Id: I285a5b39df0fd4205c830e3a9d2aa07129584bba --- M .gitignore M Sentry.php M SentryHooks.php A composer.json 4 files changed, 45 insertions(+), 1 deletion(-) Approvals: Gergő Tisza: Looks good to me, approved jenkins-bot: Verified diff --git a/.gitignore b/.gitignore index 3c3629e..e32f354 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ -node_modules +node_modules/ +vendor/ +composer.lock + diff --git a/Sentry.php b/Sentry.php index f80f939..607ffdc 100644 --- a/Sentry.php +++ b/Sentry.php @@ -31,6 +31,8 @@ $wgHooks['BeforePageDisplay'][] = 'SentryHooks::onBeforePageDisplay'; $wgHooks['UnitTestsList'][] = 'SentryHooks::onUnitTestsList'; $wgHooks['ResourceLoaderTestModules'][] = 'SentryHooks::onResourceLoaderTestModules'; +$wgHooks['LogException'][] = 'SentryHooks::onLogException'; +SentryHooks::onRegistration(); /** * Sentry DSN (http://raven.readthedocs.org/en/latest/config/#the-sentry-dsn) @@ -52,3 +54,9 @@ */ $wgSentryLogOnError = true; +/** + * Log PHP errors automatically. + * @var bool + */ +$wgSentryLogPhpErrors = true; + diff --git a/SentryHooks.php b/SentryHooks.php index c653f8a..d8b8031 100644 --- a/SentryHooks.php +++ b/SentryHooks.php @@ -56,4 +56,24 @@ } return substr( $dsn, 0, $colon_pos ) . substr( $dsn, $at_pos ); } + + public static function onRegistration() { + if ( file_exists( __DIR__ . '/vendor/autoload.php' ) ) { + require_once( __DIR__ . '/vendor/autoload.php' ); + } + } + + public static function onLogException( Exception $e ) { + global $wgSentryDsn, $wgSentryLogPhpErrors; + + if ( !$wgSentryLogPhpErrors ) { + return true; + } + + $client = new Raven_Client( $wgSentryDsn ); + $client->captureException( $e ); + + return true; + } } + diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..b07f188 --- /dev/null +++ b/composer.json @@ -0,0 +1,13 @@ +{ + "name": "mediawiki/sentry", + "type": "mediawiki-extension", + "description": "Send MediaWiki errors to Sentry, a realtime, platform-agnostic error logging and aggregation platform", + "keywords": ["MediaWiki", "Sentry", "error logging"], + "homepage": "https://www.mediawiki.org/wiki/Extension:Sentry", + "license" : "MIT", + + "require": { + "composer/installers": ">=1.0.1", + "raven/raven": "0.12.0" + } +} -- To view, visit https://gerrit.wikimedia.org/r/213469 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I285a5b39df0fd4205c830e3a9d2aa07129584bba Gerrit-PatchSet: 4 Gerrit-Project: mediawiki/extensions/Sentry Gerrit-Branch: master Gerrit-Owner: Edlira <[email protected]> Gerrit-Reviewer: Gergő Tisza <[email protected]> Gerrit-Reviewer: Legoktm <[email protected]> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
