function sendSentryMessage($message)
{
    $CI =& get_instance();
    $client = new Raven_Client($CI->config->item('sentry_client_id'));
    $client->getIdent($client->captureMessage($message));
    $client->context->clear();
}
Esempio n. 2
0
 /**
  * @param \Exception $e
  */
 public function handleYiiExceptions($e)
 {
     if ($this->canLogException($e)) {
         $e->event_id = $this->client->getIdent($this->client->captureException($e));
     }
     if ($this->oldExceptionHandler) {
         call_user_func($this->oldExceptionHandler, $e);
     }
 }
 public function captureException($exception, $culpritOrOptions = null, $logger = null, $vars = null)
 {
     $eventId = $this->client->captureException($exception, $culpritOrOptions, $logger, $vars);
     if ($eventId) {
         $ident = $this->client->getIdent($eventId);
         $this->recorder->addExceptionEventId($exception, $ident);
     }
     return $eventId;
 }
Esempio n. 4
0
 /**
  * Log a message to the logs.
  *
  * @param string $level
  * @param mixed  $message
  * @param array  $context
  *
  * @return void
  */
 public function log($level, $message, array $context = [])
 {
     $this->sentry->context->clear();
     if ($user = $this->resolveCurrentUser()) {
         $this->sentry->user_context($user);
     }
     $this->sentry->extra_context($context);
     $level = $this->getSeverity($level);
     if ($message instanceof Exception) {
         $this->sentry->getIdent($this->sentry->captureException($message, ['level' => $level]));
     } else {
         $msg = $this->formatMessage($message);
         $this->sentry->getIdent($this->sentry->captureMessage($msg, [], ['level' => $level]));
     }
 }
Esempio n. 5
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();
         }
     }]);
 }
 /**
  * Send the exception to Sentry
  *
  * @param Exception $exception
  * @return String|null Event id for the Sentry event
  */
 private static function sentryCapture($exception)
 {
     try {
         Raven_Autoloader::register();
         // Instantiate the client if it hasn't already been created
         if (self::$_client === null) {
             $options = Configure::read('Sentry.options');
             if (empty($options)) {
                 $options = array();
             }
             self::$_client = new Raven_Client(Configure::read('Sentry.DSN.PHP'), $options);
         }
         self::setUserContext();
         $event = self::$_client->captureException($exception, get_class($exception), 'PHP');
         return self::$_client->getIdent($event);
     } catch (Exception $e) {
         parent::handleException($e);
     }
     return null;
 }
Esempio n. 7
0
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();
        $smarty->assign('config', $config->get_all());
        $smarty->compile_dir = DATA_ROOT . 'templates_c';
        $smarty->assign('event_id', $event_id);
        $smarty->assign('support_email', SUPPORT_EMAIL);
        $email_body = "uzERP Exception logged to sentry with ID: " . $event_id;
        $smarty->assign('email_body', rawurlencode($email_body));
        $smarty->display(STANDARD_TPL_ROOT . 'error.tpl');
    } catch (Exception $e) {
        // If something went wrong, just continue.
    }
}
Esempio n. 8
0
 /**
  * Logs a query to Sentry.
  * @param string $query query to log.
  * @param integer $level log level.
  * @param string $engine name of the sql driver.
  * @return string event id (or null if not captured).
  * @throws Exception if logging the query fails.
  */
 public function captureQuery($query, $level = Logger::LEVEL_INFO, $engine = '')
 {
     if (!$this->isEnvironmentEnabled()) {
         return null;
     }
     try {
         $eventId = $this->_client->getIdent($this->_client->captureQuery($query, $level, $engine));
     } catch (\Exception $e) {
         if (YII_DEBUG) {
             throw new Exception('SentryClient failed to log query: ' . $e->getMessage(), (int) $e->getCode());
         } else {
             $this->log($e->getMessage(), Logger::LEVEL_ERROR);
             throw new Exception('SentryClient failed to log query.', (int) $e->getCode());
         }
     }
     $this->_loggedEventIds[] = $eventId;
     $this->log(sprintf('Query logged to Sentry with event id: %d', $eventId), Logger::LEVEL_INFO);
     return $eventId;
 }
|--------------------------------------------------------------------------
| 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.
|
*/
App::error(function (Exception $exception, $code) {
    if (Config::get('sentry.enabled') === true) {
        // Instantiate a new client with a compatible DSN
        $client = new Raven_Client(Config::get('sentry.dsn'));
        $client->getIdent($client->captureException($exception));
    }
    if (Config::get('app.debug') == true) {
        if (Request::is('api/*')) {
            return Api::error($exception->getMessage(), $code);
        }
        Log::error($exception);
    } else {
        if (Request::is('api/*')) {
            return Api::error(Lang::get('500'), $code);
        }
        return Response::view('errors.error', array(), $code);
    }
});
/*
|---------------------------------
Esempio n. 10
0
 /**
  * Send errors to a remote Sentry server with level = warning
  * 
  * @param array $ferrors
  * 
  * @return void
  */
 private function sentrySend($ferrors)
 {
     //ignore if no username or nagios request
     if (EGS_USERNAME or strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'nagios') !== false) {
         try {
             $client = new Raven_Client(SENTRY_DSN, array('curl_method' => 'async', 'verify_ssl' => FALSE));
             // Capture the flash errors and send to Sentry
             $client->user_context(array('username' => EGS_USERNAME));
             $client->tags_context(array('source' => 'flash'));
             $cc = 0;
             foreach ($ferrors as $ferror) {
                 $cc++;
                 $client->extra_context(array('error ' . $cc => $ferror));
             }
             if ($cc != 0) {
                 $event_id = $client->getIdent($client->captureMessage($ferrors[0], array(), 'warning'));
             }
         } catch (Exception $e) {
             //If something went wrong, just continue.
         }
     }
 }
Esempio n. 11
0
 /**
  * @param \Exception $ex
  * @param array $extra
  */
 public function logException(\Exception $ex, $tags = array(), $extra = array())
 {
     $ravenClient = new \Raven_Client('https://*****:*****@app.getsentry.com/49959');
     $tags['php_version'] = phpversion();
     $tags['skylab_version'] = \Kunstmaan\Skylab\Application::VERSION;
     $tags['user'] = posix_getpwuid(posix_geteuid())['name'];
     $extra = array_merge($extra, $this->app["config"]);
     if (\Kunstmaan\Skylab\Application::VERSION !== "@package_version@") {
         $event_id = $ravenClient->getIdent($ravenClient->captureException($ex, array('extra' => $extra, 'tags' => $tags)));
         $this->output->writeln("\n\n<error>  " . $ex->getMessage() . "\n  This exception has been reported with id {$event_id}. Please log a github issue at https://github.com/Kunstmaan/skylab/issues and mention this id.</error>\n\n");
     }
     echo $ex->getTraceAsString();
     throw $ex;
 }
Esempio n. 12
0
 /**
  * Given an identifier, returns a Sentry searchable string.
  * @param integer $ident Unique identifier
  * @return string
  */
 public function getIdent($ident)
 {
     return $this->_client->getIdent($ident);
 }