Ejemplo n.º 1
0
 /**
  * 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;
     });
 }
Ejemplo n.º 2
0
 /**
  * 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');
     }
 }
Ejemplo n.º 3
0
 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();
 }
Ejemplo n.º 5
0
 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;
 }
Ejemplo n.º 6
0
 /**
  * {@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 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'));
 }
Ejemplo n.º 9
0
 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;
     });
 }
Ejemplo n.º 10
0
 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";
         }
     }
 }
Ejemplo n.º 11
0
 *   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
    define('HTTP_HOST', $_SERVER['HTTP_HOST']);
<?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();
}
Ejemplo n.º 13
0
 /**
  * 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;
 }
Ejemplo n.º 14
0
 /**
  * @param bool $callExistingHandler
  * @return ZendSentry
  */
 public function registerExceptionHandler($callExistingHandler = true)
 {
     $this->ravenErrorHandler->registerExceptionHandler($callExistingHandler);
     return $this;
 }