Beispiel #1
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]));
     }
 }
Beispiel #2
0
 /**
  * Handle an error with Sentry
  *
  * @return string
  */
 public function handle()
 {
     // Instantiate a new Raven_Client with the configured DSN
     $client = new \Raven_Client(\Skeleton\Error\Config::$sentry_dsn);
     // Assign the session to the extra context
     if (isset($_SESSION)) {
         $client->extra_context(['session' => print_r($_SESSION, true)]);
     }
     $client->captureException($this->exception);
 }
Beispiel #3
0
 /**
  * @param string $command
  * @param int[] $expectedExitCodes
  * @return int
  */
 public function execWithLogging($command, $expectedExitCodes = array(0))
 {
     $shutUp = ' >/dev/null 2>&1';
     exec($command . $shutUp, $output, $exitCode);
     if (array_search($exitCode, $expectedExitCodes) === false) {
         $executable = explode(' ', $command, 2);
         $executable = reset($executable);
         if ($this->ravenClient) {
             $this->ravenClient->extra_context(array('command' => $command . $shutUp, 'output' => $output, 'exitCode' => $exitCode));
             $this->ravenClient->captureException(new \Exception("{$executable} executed with error"));
         }
         return $exitCode;
     }
     return $exitCode;
 }
<?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();
}
Beispiel #5
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.
         }
     }
 }