/** * 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 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')); }
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(); } }]); }
/** * 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'); } }
private function setHandlers() { $error_handler = new Raven_ErrorHandler($this); $error_handler->registerErrorHandler(); $error_handler->registerExceptionHandler(); $error_handler->registerShutdownFunction(); }
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); }
/** * 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); } }
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(); } }
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')); }
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; }); }
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"; } } }
* * @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 define('HTTP_HOST', $_SERVER['HTTP_HOST']); } else {
<?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); }
/** * 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; }
|-------------------------------------------------------------------------- | Application Error Handler |-------------------------------------------------------------------------- | | Here you may handle any errors that occur in your application, including | logging them or displaying custom views for specific errors. You may | even register several error handlers to handle different types of | exceptions. If nothing is returned, the default error view is | shown, which includes a detailed stack trace during debug. | */ if (Config::get('app.sentry_api') && !Config::get('app.debug')) { $raven_client = new Raven_Client(Config::get('app.sentry_api')); $raven_error_handler = new Raven_ErrorHandler($raven_client); $raven_error_handler->registerExceptionHandler(); $raven_error_handler->registerErrorHandler(); $raven_error_handler->registerShutdownFunction(); } /* |-------------------------------------------------------------------------- | Maintenance Mode Handler |-------------------------------------------------------------------------- | | The "down" Artisan command gives you the ability to put an application | into maintenance mode. Here, you will define what is displayed back | to the user if maintenance mode is in effect for the application. | */ App::down(function () { return Response::make("Be right back!", 503); });
/** * @param bool $callExistingHandler * @param int $errorReporting * * @return ZendSentry */ public function registerErrorHandler($callExistingHandler = true, $errorReporting = E_ALL) { $this->ravenErrorHandler->registerErrorHandler($callExistingHandler, $errorReporting); return $this; }