Edlira has uploaded a new change for review. https://gerrit.wikimedia.org/r/213469
Change subject: Add PHP error logging to Sentry extension ...................................................................... Add PHP error logging to Sentry extension Bug: T85188 Change-Id: I285a5b39df0fd4205c830e3a9d2aa07129584bba --- M .gitignore A Composer.json M Sentry.php M SentryHooks.php 4 files changed, 42 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Sentry refs/changes/69/213469/1 diff --git a/.gitignore b/.gitignore index 3c3629e..e96cdac 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ node_modules +vendor/ +composer.lock diff --git a/Composer.json b/Composer.json new file mode 100644 index 0000000..600c92f --- /dev/null +++ b/Composer.json @@ -0,0 +1,12 @@ +{ + "name": "mediawiki/sentry", + "type": "mediawiki-extension", + "description": "Integration of mediawiki to Sentry, an Realtime, platform-agnosticerror logging and aggregation platform", + "homepage": "https://www.mediawiki.org/wiki/Extension:Sentry", + "license" : "GPL-2.0+", + + "require": { + "composer/installers": ">=1.0.1", + "raven/raven": "0.12.0" + } +} \ No newline at end of file diff --git a/Sentry.php b/Sentry.php index f80f939..576413d 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 uncaught PHP errors automatically. + * @var bool + */ +$wgSentryPHPLogOnError = true; + diff --git a/SentryHooks.php b/SentryHooks.php index c653f8a..e7e99ce 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, $wgSentryPHPLogOnError; + if (!$wgSentryPHPLogOnError) { + return true; + } + $client = new Raven_Client($wgSentryDsn); + // Capture an exception and Provide some additional data with an exception + $event_id = $client->getIdent($client->captureException($e, array( + 'extra' => array( + 'php_version' => phpversion() + ), + ))); + return true; + } } -- To view, visit https://gerrit.wikimedia.org/r/213469 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I285a5b39df0fd4205c830e3a9d2aa07129584bba Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Sentry Gerrit-Branch: master Gerrit-Owner: Edlira <edlira.dus...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits