private function setHandlers() { $error_handler = new Raven_ErrorHandler($this); $error_handler->registerErrorHandler(); $error_handler->registerExceptionHandler(); $error_handler->registerShutdownFunction(); }
/** * Registers exception handler to the Sentry. * * @return void */ function sentry_register() { $extConf = @unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['sentry']); if (is_array($extConf) && isset($extConf['sentryDSN'])) { // Register Raven autoloader $ravenPhpAutoloaderPath = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('sentry', 'lib/raven-php/lib/Raven/Autoloader.php'); /** @noinspection PhpIncludeInspection */ require_once $ravenPhpAutoloaderPath; Raven_Autoloader::register(); // Set error handler $GLOBALS['SENTRY_CLIENT'] = new Raven_Client($extConf['sentryDSN']); $ravenErrorHandler = new Raven_ErrorHandler($GLOBALS['SENTRY_CLIENT']); $errorMask = E_ALL & ~(E_DEPRECATED | E_NOTICE | E_STRICT); // Register handlers in case if we do not have to report to TYPO3. Otherwise we need to register those handlers first! if (!$extConf['passErrorsToTypo3']) { $ravenErrorHandler->registerErrorHandler(FALSE, $errorMask); $ravenErrorHandler->registerExceptionHandler(FALSE); } // Make sure that TYPO3 does not override our handler \DmitryDulepov\Sentry\ErrorHandlers\SentryErrorHandler::initialize($ravenErrorHandler, $errorMask); \DmitryDulepov\Sentry\ErrorHandlers\SentryExceptionHandler::initialize($ravenErrorHandler); // TYPO3 7.0 \DmitryDulepov\Sentry\ErrorHandlers\SentryExceptionHandlerFrontend::initialize($ravenErrorHandler); // Register test plugin if (is_array($extConf) && isset($extConf['enableTestPlugin']) && $extConf['enableTestPlugin']) { \TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin('DmitryDulepov.sentry', 'ErrorHandlerTest', array('ErrorHandlerTest' => 'index,phpWarning,phpError,phpException'), array('ErrorHandlerTest' => 'index,phpWarning,phpError,phpException')); } unset($extConf); // Fix TYPO3 7.0 hard-coded FE exception handler $GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects']['TYPO3\\CMS\\Frontend\\ContentObject\\Exception\\ProductionExceptionHandler'] = array('className' => 'DmitryDulepov\\Sentry\\ErrorHandlers\\SentryExceptionHandlerFrontend'); } }
protected function execute(InputInterface $input, OutputInterface $output) { $config = $this->setConfiguraton($input); $client = new \GuzzleHttp\Client(['defaults' => ['allow_redirects' => false, 'timeout' => 5, 'connect_timeout' => 5]]); /** @var Instance $instance */ foreach ($config->getInstances() as $instance) { $requests[] = $client->createRequest('HEAD', $instance->getUrl()); } $options = []; Pool::send($client, $requests, ['complete' => function (CompleteEvent $event) { }, 'error' => function (ErrorEvent $event) use($config) { $instance = $config->findInstanceByUrl($event->getRequest()->getUrl()); if ($instance == null) { throw new \RuntimeException('Instance not found'); } if (!$event->getException()->hasResponse()) { $raven = new \Raven_Client($instance->getSentryDsn()); $event_id = $raven->getIdent($raven->captureMessage(sprintf('The website %s with url -> %s is down or has a problem', $instance->getName(), $event->getRequest()->getUrl()), [], \Raven_Client::FATAL)); if ($raven->getLastError() !== null) { printf('There was an error sending the event to Sentry: %s', $raven->getLastError()); } $error_handler = new \Raven_ErrorHandler($raven); $error_handler->registerExceptionHandler(); $error_handler->registerErrorHandler(); $error_handler->registerShutdownFunction(); } }]); }
/** * Initialize the raven client and fatal error handler (shutdown function) */ public function initializeObject() { $client = new \Raven_Client($this->dsn); $errorHandler = new \Raven_ErrorHandler($client, TRUE); $errorHandler->registerShutdownFunction(); $this->client = $client; $this->setTagsContext(); }
public function testExceptionsAreLogged() { $client = $this->getMock('Client', array('captureException', 'getIdent')); $client->expects($this->once())->method('captureException')->with($this->isInstanceOf('ErrorException')); $e = new ErrorException('message', 0, E_WARNING, '', 0); $handler = new Raven_ErrorHandler($client); $handler->handleException($e); }
/** * Handles exceptions thrown during rendering of content objects * The handler can decide whether to re-throw the exception or * return a nice error message for production context. * * @param \Exception $exception * @param AbstractContentObject $contentObject * @param array $contentObjectConfiguration * @return string */ public function handle(\Exception $exception, AbstractContentObject $contentObject = NULL, $contentObjectConfiguration = array()) { $this->ravenErrorHandler->handleException($exception, TRUE); $extConf = @unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['sentry']); if ($extConf['passErrorsToTypo3']) { parent::handle($exception, $contentObject, $contentObjectConfiguration); } }
/** * Registers this class as default error handler * * @param integer $errorHandlerErrors The integer representing the E_* error level which should be * @param \Raven_ErrorHandler $ravenErrorHandler Note: must be last to ensure interface compatibility! */ public function __construct($errorHandlerErrors, \Raven_ErrorHandler $ravenErrorHandler = NULL) { $extConf = @unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['sentry']); if ($extConf['passErrorsToTypo3']) { // The code below will set up a TYPO3 error handler $this->typo3ErrorHandler = GeneralUtility::makeInstance($GLOBALS['TYPO3_CONF_VARS']['SYS']['errorHandler'], $errorHandlerErrors); $ravenErrorHandler->registerErrorHandler(true, $errorHandlerErrors); } }
/** * Exception Handler * * @param Exception $exception Exception to handle * @return void */ public function handle(Exception $exception) { if (!Configure::read('CakeMonitor.Sentry.enabled') || error_reporting() === 0) { return false; } $errorHandler = new \Raven_ErrorHandler($this->_ravenClient); $errorHandler->registerShutdownFunction(); $errorHandler->handleException($exception); }
public function testErrorHandlerDefaultsErrorReporting() { $client = $this->getMock('Client', array('captureException', 'getIdent')); $client->expects($this->never())->method('captureException'); error_reporting(E_USER_ERROR); $handler = new Raven_ErrorHandler($client); $handler->registerErrorHandler(false); trigger_error('Warning', E_USER_WARNING); }
public static function init($sentryDSN) { $client = new Raven_Client($sentryDSN); // Install error handlers and shutdown function to catch fatal errors $error_handler = new Raven_ErrorHandler($client); $error_handler->registerExceptionHandler(); $error_handler->registerErrorHandler(); $error_handler->registerShutdownFunction(); self::$client = $client; }
/** * {@inheritDoc} */ public function register(SilexApplication $app) { if ($dsn = getenv('SENTRY_DSN')) { $app['raven.client'] = $client = new \Raven_Client($dsn); $errorHandler = new \Raven_ErrorHandler($client); $errorHandler->registerExceptionHandler(); $errorHandler->registerErrorHandler(); $errorHandler->registerShutdownFunction(); } }
/** * Constructs this exception handler - registers itself as the default exception handler. * * @param \Raven_ErrorHandler $ravenErrorHandler Note: must accept NULL because of compatiblity with the interface */ public function __construct(\Raven_ErrorHandler $ravenErrorHandler = NULL) { $extConf = @unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['sentry']); if ($extConf['passErrorsToTypo3']) { // The code below will set up a TYPO3 exception handler GeneralUtility::makeInstance($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['errors']['exceptionHandler']); // We always register exception handler for Sentry, regardless of TYPO3 settings! $ravenErrorHandler->registerExceptionHandler(true); } }
public function init() { parent::init(); $this->client = new \Raven_Client($this->dsn, $this->clientOptions); $this->ravenErrorHandler = new \Raven_ErrorHandler($this->client); $this->ravenErrorHandler->registerErrorHandler(true); // shutdown function not working in yii2 yet: https://github.com/yiisoft/yii2/issues/6637 //$this->ravenErrorHandler->registerShutdownFunction(); $this->oldExceptionHandler = set_exception_handler(array($this, 'handleYiiExceptions')); }
/** * Initialize the raven client and fatal error handler (shutdown function) */ public function initializeObject() { $options = array(); if (getenv('GIT_REV')) { // this is automatically injected by Dokku deployments $options['release'] = getenv('GIT_REV'); } $client = new \Raven_Client($this->dsn, $options); $errorHandler = new \Raven_ErrorHandler($client, TRUE); $errorHandler->registerShutdownFunction(); $this->client = $client; $this->setTagsContext(); }
/** * Provider registration in silex application * * @param Application $app The silex application * * @throws \InvalidArgumentException */ public function register(Application $app) { // Initialize raven client $app['raven'] = $app->share(function () use($app) { $dsn = isset($app['raven.dsn']) ? $app['raven.dsn'] : ''; $options = isset($app['raven.options']) ? $app['raven.options'] : array('logger' => 'silex-raven'); $client = new \Raven_Client($dsn, $options); $errorHandler = new \Raven_ErrorHandler($client); if (isset($app['raven.handle'])) { // Register exception handler if (!array_key_exists('exceptions', $app['raven.handle']) || $app['raven.handle']['exceptions']) { $errorHandler->registerExceptionHandler(); } // Register error handler if (!array_key_exists('errors', $app['raven.handle']) || $app['raven.handle']['errors']) { $errorHandler->registerErrorHandler(); } // Register shutdown function (to catch fatal errors) if (!array_key_exists('fatal_errors', $app['raven.handle']) || $app['raven.handle']['fatal_errors']) { $errorHandler->registerShutdownFunction(); } } else { // Register exception handler $errorHandler->registerExceptionHandler(); // Register error handler $errorHandler->registerErrorHandler(); // Register shutdown function (to catch fatal errors) $errorHandler->registerShutdownFunction(); } return $client; }); }
public function register() { $sentry_dsn = PhabricatorEnv::getEnvConfigIfExists('sentry.dsn'); if (empty($sentry_dsn)) { return; } Raven_Autoloader::register(); // Configure the client $client = new Raven_Client($sentry_dsn); // Install error handlers $error_handler = new Raven_ErrorHandler($client); $error_handler->registerExceptionHandler(); $error_handler->registerErrorHandler(); // We can't override DarkConsole, so let's capture them at the // end of the request SentryLogger::setClient($client); register_shutdown_function(array('SentryLogger', 'logAllPendingErrors')); }
/** * Send errors to sentry server * @param CErrorEvent $event represents the parameter for the onError event. * @return boolean */ public function handleError($event) { if (!($sentry = $this->getClient())) { return false; } $this->_errorHandler->handleError($event->code, $event->message, $event->file, $event->line, $event->params); if ($lastError = $sentry->getLastError()) { Yii::log($lastError, CLogger::LEVEL_ERROR, $this->ravenLogCategory); } return true; }
public static function init(Di $di, $isDevelopment = false) { $config = $di->get('config'); $sentryDsn = ''; if (isset($config->sentry->dsn)) { $sentryDsn = $config->sentry->dsn; } $client = new \Raven_Client($sentryDsn); if ($isDevelopment) { error_reporting(E_ALL); ini_set('display_errors', 1); } else { $error_handler = new \Raven_ErrorHandler($client); $error_handler->registerExceptionHandler(); $error_handler->registerErrorHandler(); $error_handler->registerShutdownFunction(); } $di->setShared(self::SERVICE_NAME, function () use($client) { return $client; }); }
$system = system::Instance(); // ******* // CONFIG // we have to load parts of system to load the config $system->check_system(); $system->load_essential(); // ************************** // ERROR REPORTING & LOGGING if (defined('SENTRY_DSN')) { // custom exception handler, sends to sentry set_exception_handler('sentry_exception_handler'); // send fatals to sentry try { $client = new Raven_Client(SENTRY_DSN, array('curl_method' => 'async', 'verify_ssl' => FALSE)); $client->tags_context(array('source' => 'fatal')); $error_handler = new Raven_ErrorHandler($client); $error_handler->registerShutdownFunction(); } catch (Exception $e) { // If something went wrong, just continue. } } else { // custom exception handler, show error to user set_exception_handler('uzerp_exception_handler'); } function sentry_exception_handler($exception) { try { $client = new Raven_Client(SENTRY_DSN, array('curl_method' => 'async', 'verify_ssl' => FALSE)); $client->tags_context(array('source' => 'exception')); $config = Config::Instance(); $event_id = $client->getIdent($client->captureException($exception, array('extra' => array('uzerp_version' => $config->get('SYSTEM_VERSION')))));
public function initSentry() { if ($this->sentryDSN) { try { $this->ravenClient = new \Raven_Client($this->sentryDSN); $error_handler = new \Raven_ErrorHandler($this->ravenClient); $error_handler->registerExceptionHandler(); $error_handler->registerErrorHandler(); $error_handler->registerShutdownFunction(); } catch (\InvalidArgumentException $e) { echo "sentryDSN is invalid\n"; } } }
* string SENTRY_API_URL * string BASE_PATH * * @package Garp * @author Harmen Janssen <*****@*****.**> * @author David Spreekmeester <*****@*****.**> */ if (!defined('BASE_PATH')) { define('BASE_PATH', realpath(dirname(__FILE__) . '/../..')); } define('APPLICATION_PATH', BASE_PATH . '/application'); define('GARP_APPLICATION_PATH', realpath(dirname(__FILE__))); // Sentry integration if (defined('SENTRY_API_URL') && APPLICATION_ENV !== 'development') { $ravenClient = new Raven_Client(SENTRY_API_URL); $ravenErrorHandler = new Raven_ErrorHandler($ravenClient); $ravenErrorHandler->registerExceptionHandler(); $ravenErrorHandler->registerErrorHandler(); $ravenErrorHandler->registerShutdownFunction(); Zend_Registry::set('RavenClient', $ravenClient); } $appSpecificInit = APPLICATION_PATH . '/configs/init.php'; if (file_exists($appSpecificInit)) { include_once $appSpecificInit; } defined('READ_FROM_CACHE') || define('READ_FROM_CACHE', true); defined('MEMCACHE_HOST') || define('MEMCACHE_HOST', '127.0.0.1'); defined('MEMCACHE_PORT') || define('MEMCACHE_PORT', '11211'); $isCli = false; if (array_key_exists('HTTP_HOST', $_SERVER) && $_SERVER['HTTP_HOST']) { // h t t p c o n t e x t
<?php if (!defined('BASEPATH')) { exit('No direct script access allowed'); } if (!defined('__DIR__')) { define('__DIR__', dirname(__FILE__)); } $CI =& get_instance(); $_SERVER['APP_ENV'] = ENVIRONMENT; // /application/third_party/raven-php/lib/Raven/Autoloader.php require_once __DIR__ . '/raven-php/lib/Raven/Autoloader.php'; Raven_Autoloader::register(); $this->config->load('sentry'); if ($CI->config->item('sentry_enabled') !== false) { $client = new Raven_Client($CI->config->item('sentry_client_id')); $client->tags_context(array('Environment' => ENVIRONMENT, 'php_version' => phpversion())); $client->extra_context(array('session' => $CI->session->all_userdata(), 'last_query' => $CI->db->last_query(), 'queries' => $CI->db->queries)); // Install error handlers and shutdown function to catch fatal errors $error_handler = new Raven_ErrorHandler($client); $error_handler->registerExceptionHandler(); $error_handler->registerErrorHandler(); $error_handler->registerShutdownFunction(); } function sendSentryMessage($message) { $CI =& get_instance(); $client = new Raven_Client($CI->config->item('sentry_client_id')); $client->getIdent($client->captureMessage($message)); $client->context->clear(); }
public function testFluidInterface() { $client = $this->getMock('Client', array('captureException', 'getIdent')); $handler = new Raven_ErrorHandler($client); $result = $handler->registerErrorHandler(); $this->assertEquals($result, $handler); $result = $handler->registerExceptionHandler(); $this->assertEquals($result, $handler); // TODO(dcramer): cant find a great way to test resetting the shutdown // handler // $result = $handler->registerShutdownHandler(); // $this->assertEquals($result, $handler); }
/** * @param int $reservedMemorySize * @return ZendSentry */ public function registerShutdownFunction($reservedMemorySize = 10) { $this->ravenErrorHandler->registerShutdownFunction($reservedMemorySize); return $this; }
/** * Return if configuration is valid * * @return array Array of errors. Empty array if ok. */ public function checkConfiguration() { global $conf; $errors = array(); $dsn = $conf->global->SYSLOG_SENTRY_DSN; try { $client = new Raven_Client($dsn, array('curl_method' => 'sync')); } catch (InvalidArgumentException $ex) { $errors[] = "ERROR: There was an error parsing your DSN:\n " . $ex->getMessage(); } if (!$errors) { // Send test event and check for errors $client->captureMessage('TEST: Sentry syslog configuration check', null, Raven_Client::DEBUG); $last_error = $client->getLastError(); if ($last_error) { $errors[] = $last_error; } } if (!$errors) { // Install handlers $error_handler = new Raven_ErrorHandler($client); $error_handler->registerExceptionHandler(); $error_handler->registerErrorHandler(); $error_handler->registerShutdownFunction(); } return $errors; }