/** * 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; }); }
/** * Initializes the route. * This method is invoked after the route is created by the route manager. * @return void */ public function init() { parent::init(); if ((empty($this->levels) || stristr($this->levels, 'error') !== false) && $this->getClient() !== false) { Yii::app()->attachEventHandler('onException', array($this, 'handleException')); Yii::app()->attachEventHandler('onError', array($this, 'handleError')); $this->_errorHandler = new Raven_ErrorHandler($this->getClient()->getRavenClient()); $this->_errorHandler->registerShutdownFunction(); } }
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(); } }]); }
private function setHandlers() { $error_handler = new Raven_ErrorHandler($this); $error_handler->registerErrorHandler(); $error_handler->registerExceptionHandler(); $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(); }
/** * 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 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(); } }
/** * 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(); }
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; }); }
// ******* // 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'))))); $smarty = new Smarty();
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 { // c l i c o n t e x t
/** * 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; }
/** * @param int $reservedMemorySize * @return ZendSentry */ public function registerShutdownFunction($reservedMemorySize = 10) { $this->ravenErrorHandler->registerShutdownFunction($reservedMemorySize); return $this; }