示例#1
0
 /**
  * {@inheritdoc}
  */
 public function export()
 {
     foreach ($this->messages as $message) {
         list($context, $level, $category, $timestamp, $traces) = $message;
         $extra = [];
         if ($context instanceof \Throwable || $context instanceof \Exception) {
             $this->client->captureException($context);
             $description = $context->getMessage();
         } elseif (isset($context['msg'])) {
             $description = $context['msg'];
             $extra = $context;
             unset($extra['msg']);
         } else {
             $description = $context;
         }
         if ($this->context) {
             $extra['context'] = parent::getContextMessage();
         }
         if (is_callable($this->extraCallback)) {
             $extra = call_user_func($this->extraCallback, $context, $extra);
         }
         $data = ['level' => static::getLevelName($level), 'timestamp' => $timestamp, 'message' => $description, 'extra' => $extra, 'tags' => ['category' => $category]];
         $this->client->capture($data, $traces);
     }
 }
示例#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;
 }
 /**
  * Explicitly handle an exception, should be called from an exception handler (in Flow or TypoScript)
  *
  * @param \Exception $exception The exception to capture
  * @param array $extraData Additional data passed to the Sentry sample
  */
 public function handleException(\Exception $exception, array $extraData = array())
 {
     $this->setUserContext();
     $tags = array('code' => $exception->getCode());
     if ($exception instanceof \TYPO3\Flow\Exception) {
         $extraData['referenceCode'] = $exception->getReferenceCode();
     }
     $this->client->captureException($exception, array('extra' => $extraData, 'tags' => $tags));
 }
示例#5
0
 public function handle($e)
 {
     if ($e instanceof ErrorException) {
         $level = $e->getSeverity();
     } else {
         $level = E_ERROR;
     }
     if ($this->minimumLogLevel & $level) {
         $this->client->captureException($e);
     }
 }
示例#6
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]));
     }
 }
 /**
  * Explicitly handle an exception, should be called from an exception handler (in Flow or TypoScript)
  *
  * @param object $exception The exception to capture
  * @param array $extraData Additional data passed to the Sentry sample
  */
 public function handleException($exception, array $extraData = array())
 {
     // TODO: Handle PHP7 Throwable
     if (!$exception instanceof \Exception) {
         return;
     }
     $this->setUserContext();
     $tags = array('code' => $exception->getCode());
     if ($exception instanceof \TYPO3\Flow\Exception) {
         $extraData['referenceCode'] = $exception->getReferenceCode();
     }
     if ($this->client) {
         // safeguard; for some reasons, during cache:warmup, $this->client is not set.
         $this->client->captureException($exception, array('extra' => $extraData, 'tags' => $tags));
     }
 }
 /**
  * Create a new image element from an email address.
  * @param  string  $email The email address.
  * @param  integer $size  The avatar size.
  * @return string The source for an image element.
  */
 public static function log($ex)
 {
     // Instantiate a new client with a compatible DSN
     $client = new Raven_Client(Config::get('raven::raven.url'));
     // Capture an exception
     $client->captureException($ex);
 }
示例#9
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);
 }
 /**
  * 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;
 }
示例#11
0
 /**
  * Logs an exception to Sentry.
  * @param Exception $exception exception to log.
  * @param array $options capture options that can contain the following structure:
  *   culprit: (string) function call that caused the event
  *   extra: (array) additional metadata to store with the event
  * @param string $logger name of the logger.
  * @param mixed $context exception context.
  * @return string event id (or null if not captured).
  * @throws Exception if logging the exception fails.
  */
 public function captureException($exception, $options = [], $logger = '', $context = null)
 {
     if (!$this->isEnvironmentEnabled()) {
         return null;
     }
     $this->processOptions($options);
     $eventId = $this->_client->getIdent($this->_client->captureException($exception, $options, $logger, $context));
     try {
     } catch (\Exception $e) {
         if (YII_DEBUG) {
             throw new Exception('SentryClient failed to log exception: ' . $exception->getMessage(), (int) $exception->getCode());
         } else {
             $this->log($e->getMessage(), Logger::LEVEL_ERROR);
             throw new Exception('SentryClient failed to log exception.', (int) $e->getCode());
         }
     }
     $this->_loggedEventIds[] = $eventId;
     $this->log(sprintf('Exception logged to Sentry with event id: %d', $eventId), Logger::LEVEL_INFO);
     return $eventId;
 }
示例#12
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;
 }
示例#13
0
文件: index.php 项目: uzerpllp/uzerp
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.
    }
}
|--------------------------------------------------------------------------
| 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);
    }
});
/*
|---------------------------------
示例#15
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;
 }
示例#16
0
文件: index.php 项目: shomimn/builder
    try {
        $app['settings'] = $app['illuminate.db']->table('settings')->lists('value', 'name');
        $app['settingsJSON'] = json_encode($app['settings']);
    } catch (Exception $e) {
        $app['settings'] = array();
        $app['settingsJSON'] = json_encode($app['settings']);
    }
    require_once __DIR__ . '/backend/builder/routes.php';
}
/*
|--------------------------------------------------------------------------
| Register error handlers
|--------------------------------------------------------------------------
*/
$app->error(function (\Exception $e, $code) use($app) {
    if (!isset($app['base_url'])) {
        $app['base_url'] = rtrim($app['request']->getSchemeAndHttpHost() . $app['request']->getBaseUrl(), '/');
    }
    if ($code === 404) {
        return new Symfony\Component\HttpFoundation\Response($app['twig']->render('404.twig.html'));
    }
    if ($app['is_demo'] && $app['installed']) {
        $user = $app['sentry']->getUser();
        $client = new Raven_Client('');
        if ($user) {
            $client->user_context($user->toArray());
        }
        $client->captureException($e);
    }
});
$app->run();
示例#17
0
文件: init.php 项目: jonthornton/JMVC
 public static function notify_admin($e)
 {
     if (defined(SENTRY_ENDPOINT)) {
         require_once JMVC_DIR . 'Raven/Client.php';
         require_once JMVC_DIR . 'Raven/Compat.php';
         require_once JMVC_DIR . 'Raven/Stacktrace.php';
         $client = new Raven_Client(SENTRY_ENDPOINT);
         $client->captureException($e);
         exit;
     }
     $file = $e->getFile();
     $message = self::make_error_report($e->getFile(), $e->getLine(), $e->getMessage());
     self::log(date('r') . "\n" . $message, 'php_errors');
     $lockfile = LOG_DIR . '/error_state';
     $last_notification = file_exists($lockfile) ? filemtime($lockfile) : 0;
     if ($last_notification == 0 || DEFINED('ADMIN_ALERT_FREQ') && time() - $last_notification > ADMIN_ALERT_FREQ) {
         touch($lockfile);
         mail(ADMIN_EMAIL, 'Error in ' . $file, $message);
         if (defined('ADMIN_ALERT')) {
             mail(ADMIN_ALERT, 'Error on ' . $_SERVER['HTTP_HOST'], 'check email');
         }
     }
 }
示例#18
0
 /**
  * @param $e
  */
 public function onFatalError($e)
 {
     if ($this->enabled) {
         $this->raven->captureException($e);
     }
 }
示例#19
0
 public function notify(atsumi_Observable $sender, atsumi_EventArgs $args)
 {
     $client = new Raven_Client($this->dsn, array('release' => $this->release, 'tags' => $this->tags));
     $client->captureException($args->exception);
 }