diff --git a/Classes/ClientProvider.php b/Classes/ClientProvider.php index 6ce33d3..4a7a00d 100644 --- a/Classes/ClientProvider.php +++ b/Classes/ClientProvider.php @@ -1,5 +1,5 @@ user_context(static::getUserContext()); $client->tags_context(static::getTagsContext()); + $client->setRelease(getenv('APP_VERSION')); return $client; } else { diff --git a/Classes/DebugExceptionHandler.php b/Classes/DebugExceptionHandler.php index 0dfb022..a301f1b 100644 --- a/Classes/DebugExceptionHandler.php +++ b/Classes/DebugExceptionHandler.php @@ -1,13 +1,6 @@ = 7.0) object. - * @TODO #72293 This will change to \Throwable only if we are >= PHP7.0 only * * @throws \Exception */ - public function handleException($exception) + public function handleException(\Throwable $exception) { ClientProvider::captureException($exception); diff --git a/Classes/ErrorHandler.php b/Classes/ErrorHandler.php index 501bc02..4cdc092 100644 --- a/Classes/ErrorHandler.php +++ b/Classes/ErrorHandler.php @@ -6,7 +6,7 @@ * Time: 11:43 */ -namespace Iresults\SentryClient; +namespace SentryClient; class ErrorHandler extends \TYPO3\CMS\Core\Error\ErrorHandler diff --git a/Classes/ProductionExceptionHandler.php b/Classes/ProductionExceptionHandler.php index f274a0e..73cf63a 100644 --- a/Classes/ProductionExceptionHandler.php +++ b/Classes/ProductionExceptionHandler.php @@ -1,25 +1,13 @@ = 7.0) object. - * @TODO #72293 This will change to \Throwable only if we are >= PHP7.0 only - * - * @throws \Exception + * @param \Exception|\Throwable $exception */ - public function handleException($exception) + public function handleException(\Throwable $exception) { ClientProvider::captureException($exception); diff --git a/Configuration/TypoScript/setup.txt b/Configuration/TypoScript/setup.txt new file mode 100644 index 0000000..fa4f1e0 --- /dev/null +++ b/Configuration/TypoScript/setup.txt @@ -0,0 +1,3 @@ +# Allow Sentry to log exceptions in frontend when rendering content. +# See: https://docs.typo3.org/typo3cms/TyposcriptReference/Setup/Config/Index.html#contentobjectexceptionhandler +config.contentObjectExceptionHandler = 0 diff --git a/README.md b/README.md index bc6915e..992c407 100644 --- a/README.md +++ b/README.md @@ -1,38 +1,120 @@ Sentry Client for TYPO3 ======================= -This is a TYPO3 Extension for exception logging with sentry, see http://www.getsentry.com +A TYPO3 extension for PHP exception logging with Sentry, https://www.sentry.io -It's based on https://github.com/getsentry/sentry-php +Logs frontend PHP errors and exceptions to your Sentry instance. Note that +logging backend issues is not yet supported by TYPO3 (it's on the todo list +for v9, according to core developer Markus Klein). +Based on the official Sentry PHP client, +[`sentry/sentry`](https://packagist.org/packages/sentry/sentry). Installation ------------ -1. Clone the repository - ```bash - git clone https://github.com/iresults/sentry_client.git - ``` - -2. Install the Sentry Library (e.g. with [CunddComposer](https://github.com/cundd/CunddComposer)) +1. Add something like this to your project's `composer.json`, and run + `composer install`: -3. Register the handlers in the `Install Tool` or `typo3conf/AdditionalConfiguration.php` - ```php - $GLOBALS['TYPO3_CONF_VARS']['SYS']['debugExceptionHandler'] = 'Iresults\\SentryClient\\DebugExceptionHandler'; - $GLOBALS['TYPO3_CONF_VARS']['SYS']['productionExceptionHandler'] = 'Iresults\\SentryClient\\ProductionExceptionHandler'; - $GLOBALS['TYPO3_CONF_VARS']['SYS']['errorHandler'] = 'Iresults\\SentryClient\\ErrorHandler'; - ``` +``` json + "repositories": [ + { + "type": "composer", + "url": "https://packagist.org/" + }, + { + "url": "https://github.com/comsolit/sentry_client.git", + "type": "git" + } + ], + "require": { + "comsolit/sentry_client": "dev-master" + } +``` +2. Make sure your `typo3conf/LocalConfiguration.php` contains something like + this in the `SYS` section: + +``` php + 'SYS' => [ + // ... + 'devIPmask' => '', + 'displayErrors' => '0', + 'enable_errorDLOG' => '1', + 'enable_exceptionDLOG' => '1', + 'enableDeprecationLog' => 'devlog', + 'systemLog' => '', + 'systemLogLevel' => '0', + 'syslogErrorReporting' => E_ALL, + 'belogErrorReporting' => E_ALL, + 'exceptionalErrors' => E_RECOVERABLE_ERROR | E_USER_DEPRECATED, + 'errorHandlerErrors' => E_WARNING | E_USER_ERROR | E_USER_WARNING | E_USER_NOTICE | E_RECOVERABLE_ERROR | E_DEPRECATED | E_USER_DEPRECATED, + 'errorHandler' => 'SentryClient\\ErrorHandler', + 'debugExceptionHandler' => 'SentryClient\\DebugExceptionHandler', + 'productionExceptionHandler' => 'SentryClient\\ProductionExceptionHandler', + ] +``` +Alternatively, you can [set those values]( +https://github.com/comsolit/sentry_client/blob/master/ext_localconf.php#L6-L19) +via the `Install Tool` or in `typo3conf/AdditionalConfiguration.php`. Configuration ------------- -Set the dsn (e.g. `http://public_key:secret_key@your-sentry-server.com/project-id`) in the `Extension Manager`. +Set the [Sentry DSN](https://docs.sentry.io/quickstart/#about-the-dsn) +(e.g. `https://public_key:secret_key@your-sentry-server.com/project-id`) +in the `Extension Manager`. + +This will be added in your `typo3conf/LocalConfiguration.php` file at: + +``` php +'EXT' => [ + 'extConf' => [ + 'sentry_client' => ... +``` + +NOTE: For professional deployments you should consider using something like +[phpdotenv](https://packagist.org/packages/vlucas/phpdotenv) to manage your +secrets instead of using the Extension Manager, and leave your +`LocalConfiguration` under version control. +JavaScript Error Logging +------------------------ + +For logging your JavaScript errors to Sentry see the [JavaScript Sentry docs]( +https://docs.sentry.io/clients/javascript/). + +If you include your JavaScript sources via TypoScript it can be handy to avoid +hard-coding and define a `SENTRY_DSN_PUBLIC` value in your system environment +(e.g. via a `.env` file read by [phpdotenv](https://packagist.org/packages/vlucas/phpdotenv)). +You can read the value in TypoScript using the [`getenv` command]( +https://docs.typo3.org/typo3cms/TyposcriptReference/DataTypes/Gettext/Index.html#getenv) +like this: + +``` typo3_typoscript +page.headerData { + 999 = COA + 999 { + 10 = TEXT + 10.value = + 20 = TEXT + 20.value = + } +} +``` Development ----------- -Development of this fork happens on https://github.com/iresults/sentry_client - -The original version can be found on https://github.com/networkteam/sentry_client \ No newline at end of file +Your contributions are welcome! Please fork the repo, make your changes, and +[open a pull request](https://github.com/comsolit/sentry_client/pulls). diff --git a/composer.json b/composer.json index ec9c667..6ce7f93 100644 --- a/composer.json +++ b/composer.json @@ -1,12 +1,14 @@ { - "name": "lemming/sentry_client", - "description": "TYPO3 Extension for exception logging with sentry, see http://www.getsentry.com", + "name": "comsolit/sentry_client", + "description": "TYPO3 extension for PHP error and exception logging with Sentry, https://sentry.io", "type": "typo3-cms-extension", + "version": "8.0.0", "require": { - "typo3/cms-core": ">=6.2.0,<8.9.99" + "typo3/cms-core": ">=6.2.0,<8.9.99", + "sentry/sentry": "^1.7" }, "license": [ - "GPL-2.0+" + "GPL-3.0+" ], "authors": [ { @@ -16,6 +18,10 @@ { "name": "Daniel Corn", "email": "daniel@iresults.li" + }, + { + "name": "Peter Bittner", + "email": "bittner@comsolit.com" } ], "replace": { @@ -24,7 +30,7 @@ }, "autoload": { "psr-4": { - "Iresults\\SentryClient\\": "Classes" + "SentryClient\\": "Classes" } } } diff --git a/cundd_composer.json b/cundd_composer.json deleted file mode 100644 index 17707c2..0000000 --- a/cundd_composer.json +++ /dev/null @@ -1,30 +0,0 @@ -{ - "name": "lemming/sentry_client", - "description": "TYPO3 Extension for exception logging with sentry, see http://www.getsentry.com", - "type": "typo3-cms-extension", - "require": { - "sentry/sentry": "^1.6" - }, - "license": [ - "GPL-2.0+" - ], - "authors": [ - { - "name": "Christoph Lehmann", - "email": "christoph.lehmann@networkteam.com" - }, - { - "name": "Daniel Corn", - "email": "daniel@iresults.li" - } - ], - "replace": { - "sentry_client": "self.version", - "typo3-ter/sentry_client": "self.version" - }, - "autoload": { - "psr-4": { - "Iresults\\SentryClient\\": "Classes" - } - } -} diff --git a/ext_emconf.php b/ext_emconf.php index 1415e11..3fe9b0d 100644 --- a/ext_emconf.php +++ b/ext_emconf.php @@ -1,28 +1,22 @@ 'Sentry Client', - 'description' => 'Sentry Client for TYPO3 - https://www.getsentry.com/', + 'description' => 'TYPO3 extension for PHP error and exception logging with Sentry, https://sentry.io', 'category' => 'services', - 'version' => '1.1.0', - 'state' => 'beta', + 'version' => '8.0.0', + 'state' => 'stable', 'uploadfolder' => false, 'createDirs' => '', 'clearcacheonload' => true, 'author' => 'Christoph Lehmann', 'author_email' => 'christoph.lehmann@networkteam.com', 'author_company' => 'networkteam GmbH', - 'constraints' => - array ( - 'depends' => - array ( - 'typo3' => '6.2.0-7.9.99', - ), - 'conflicts' => - array ( - ), - 'suggests' => - array ( - ), - ), -); + 'constraints' => [ + 'depends' => [ + 'typo3' => '6.2.0-8.9.99', + ], + 'conflicts' => [], + 'suggests' => [], + ], +]; diff --git a/ext_localconf.php b/ext_localconf.php index 329fe75..c0a8245 100644 --- a/ext_localconf.php +++ b/ext_localconf.php @@ -2,3 +2,18 @@ if (!defined('TYPO3_MODE')) { die('Access denied.'); } + +$GLOBALS['TYPO3_CONF_VARS']['SYS']['devIPmask'] = ''; // show default TYPO3 error message +$GLOBALS['TYPO3_CONF_VARS']['SYS']['displayErrors'] = '0'; // don't turn errors into exceptions, use productionExceptionHandler +$GLOBALS['TYPO3_CONF_VARS']['SYS']['enable_errorDLOG'] = '1'; // developer log ('devlog' extension) +$GLOBALS['TYPO3_CONF_VARS']['SYS']['enable_exceptionDLOG'] = '1'; // developer log ('devlog' extension) +$GLOBALS['TYPO3_CONF_VARS']['SYS']['enableDeprecationLog'] = 'devlog'; +$GLOBALS['TYPO3_CONF_VARS']['SYS']['systemLog'] = ''; // no local logging (= maximum performance) +$GLOBALS['TYPO3_CONF_VARS']['SYS']['systemLogLevel'] = '0'; // log everything +$GLOBALS['TYPO3_CONF_VARS']['SYS']['syslogErrorReporting'] = E_ALL; +$GLOBALS['TYPO3_CONF_VARS']['SYS']['belogErrorReporting'] = E_ALL; +$GLOBALS['TYPO3_CONF_VARS']['SYS']['exceptionalErrors'] = E_RECOVERABLE_ERROR | E_USER_DEPRECATED; +$GLOBALS['TYPO3_CONF_VARS']['SYS']['errorHandlerErrors'] = E_WARNING | E_USER_ERROR | E_USER_WARNING | E_USER_NOTICE | E_RECOVERABLE_ERROR | E_DEPRECATED | E_USER_DEPRECATED; +$GLOBALS['TYPO3_CONF_VARS']['SYS']['errorHandler'] = 'SentryClient\\ErrorHandler'; +$GLOBALS['TYPO3_CONF_VARS']['SYS']['debugExceptionHandler'] = 'SentryClient\\DebugExceptionHandler'; +$GLOBALS['TYPO3_CONF_VARS']['SYS']['productionExceptionHandler'] = 'SentryClient\\ProductionExceptionHandler';