Skip to content

Instantly share code, notes, and snippets.

@bwaidelich
Created April 30, 2014 08:00
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bwaidelich/bda3dfd13eb3609a8ace to your computer and use it in GitHub Desktop.
Save bwaidelich/bda3dfd13eb3609a8ace to your computer and use it in GitHub Desktop.
Using Sentry for tracking errors in TYPO3 Flow
{
"name": "your/package",
"type": "typo3-flow-package",
// ...
"require": {
"raven/raven": "*"
},
// ...
}
<?php
namespace Your\Package\Error;
/* *
* This script belongs to the TYPO3 Flow package "Your.Package". *
* *
* */
use TYPO3\Flow\Error\ProductionExceptionHandler;
/**
* Production Exception handler that reports exceptions to a configurable Sentry DSN using the raven library
*/
class SentryExceptionHandler extends ProductionExceptionHandler {
/**
* @param \Exception $exception
* @return void
*/
protected function echoExceptionWeb(\Exception $exception) {
if (isset($this->options['sentryDsn']) && strlen($this->options['sentryDsn']) > 0) {
$ravenClient = new \Raven_Client($this->options['sentryDsn']);
$ravenClient->captureException($exception);
}
parent::echoExceptionWeb($exception);
}
}
TYPO3:
Flow:
error:
exceptionHandler:
className: 'Your\Package\Error\SentryExceptionHandler'
# Sentry DSN (e.g. "http://public:secret@example.com/1")
'sentryDsn': ''
@bwaidelich
Copy link
Author

Note: Sentry is a third party tool that allows remote tracking of exceptions. See https://getsentry.com

@beelbrecht
Copy link

Loading of \Raven_Client doesn't work and resulting with a PHP fatal error:
"Fatal error: Class 'Raven_Client' not found in /path/to/My.Package/Classes/My/Package/Error/SentryExceptionHandler.php on line 24"

raven package is correctly installed with composer.
any idea?

@bwaidelich
Copy link
Author

I can't test this atm because we switched to Graylog2, maybe this helps:

  TYPO3:
    Flow:
       # disable reflection for non psr-0 compliant 3rd party packages
      object:
        excludeClasses:
         'raven.raven': ['.*']

@bwaidelich
Copy link
Author

FYI via twitter:

when using „composer install -o“ instead of „composer install“, class loading of \Raven_Client works fine

@beelbrecht
Copy link

the excludeClasses setting has no effect. only "composer install -o" works

@bwaidelich
Copy link
Author

FYI: I still have the autoloading issue on Flow master (3.0). It can be worked around by including the raven autoloader explicitly:

include_once Files::concatenatePaths(array(FLOW_PATH_PACKAGES, 'Libraries/raven/raven/lib/Raven/Autoloader.php'));
\Raven_Autoloader::register();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment