/**
  * Set tags on the raven context
  */
 protected function setTagsContext()
 {
     $objectManager = \TYPO3\Flow\Core\Bootstrap::$staticObjectManager;
     /** @var \TYPO3\Flow\Utility\Environment $environment */
     $environment = $objectManager->get('TYPO3\\Flow\\Utility\\Environment');
     $tags = array('php_version' => phpversion(), 'flow_context' => (string) $environment->getContext(), 'flow_version' => FLOW_VERSION_BRANCH);
     $this->client->tags_context($tags);
 }
Пример #2
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.
    }
}
<?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();
}
Пример #4
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.
         }
     }
 }
Пример #5
0
 /**
  * Export the message
  *
  * @param array $content Array containing the info about the message
  * @return void
  */
 public function export($content)
 {
     global $conf;
     $dsn = $conf->global->SYSLOG_SENTRY_DSN;
     $client = new Raven_Client($dsn, array('curl_method' => 'exec'));
     $client->user_context(array('username' => $content['user'] ? $content['user'] : '', 'ip_address' => $content['ip']));
     $client->tags_context(array('version' => DOL_VERSION));
     $client->registerSeverityMap(array(LOG_EMERG => Raven_Client::FATAL, LOG_ALERT => Raven_Client::FATAL, LOG_CRIT => Raven_Client::ERROR, LOG_ERR => Raven_Client::ERROR, LOG_WARNING => Raven_Client::WARNING, LOG_NOTICE => Raven_Client::WARNING, LOG_INFO => Raven_Client::INFO, LOG_DEBUG => Raven_Client::DEBUG));
     if (substr($content['message'], 0, 3) === 'sql') {
         global $db;
         $query = substr($content['message'], 4, strlen($content['message']));
         $client->captureQuery($query, $client->translateSeverity($content['level']), $db->type);
     } else {
         $client->captureMessage($content['message'], null, $client->translateSeverity($content['level']));
     }
 }