Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

This PR upgrades Sentry from used version v1.9.0 to v3.4.0 #141

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion src/app/code/community/FireGento/Logger/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public function addPriorityFilter(Zend_Log_Writer_Abstract $writer, $configPath
$priority = null;
}
}
if ( ! $configPath || ! strlen($priority)) {
if ( ! $configPath || ! strlen($priority ?? '')) {
$priority = $this->getLoggerConfig(self::XML_PATH_PRIORITY);
}
if ($priority !== null) {
Expand Down
6 changes: 3 additions & 3 deletions src/app/code/community/FireGento/Logger/Model/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,16 +183,16 @@ public function getEventDataArray()
);
}

public function offsetSet($offset, $value) {
public function offsetSet($offset, $value): void {
throw new Mage_Core_Exception('Log Event assignment not implemented');
}

public function offsetExists($offset) {
public function offsetExists($offset): bool {
$offset = $this->_underscore($offset);
return isset($this->_data[$offset]);
}

public function offsetUnset($offset) {
public function offsetUnset($offset): void {
throw new Mage_Core_Exception('Log Event assignment not implemented');
}

Expand Down
2 changes: 1 addition & 1 deletion src/app/code/community/FireGento/Logger/Model/Observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public function initLoggerClient(Varien_Event_Observer $observer)
// Allow Sentry to capture all errors, not just Mage::log
if (in_array('sentry', $targets)) {
try {
Mage::getModel('firegento_logger/sentry')->initRavenClient();
Mage::getModel('firegento_logger/sentry')->init();
} catch (Exception $e) {
Mage::logException($e);
}
Expand Down
109 changes: 52 additions & 57 deletions src/app/code/community/FireGento/Logger/Model/Sentry.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
* @license http://opensource.org/licenses/gpl-3.0 GNU General Public License, version 3 (GPLv3)
*/

use Sentry\EventHint;
use Sentry\Severity;
use function Sentry\captureException;
use function Sentry\captureMessage;

/**
* Model for Sentry logging
*
Expand All @@ -31,11 +36,6 @@
class FireGento_Logger_Model_Sentry extends FireGento_Logger_Model_Abstract
{

/**
* @var Raven_Client
*/
protected static $_ravenClient;

protected $_priorityToLevelMapping = [
0 /*Zend_Log::EMERG*/ => 'fatal',
1 /*Zend_Log::ALERT*/ => 'fatal',
Expand All @@ -49,53 +49,44 @@ class FireGento_Logger_Model_Sentry extends FireGento_Logger_Model_Abstract

protected $_fileName;

protected static $_isInitialized = false;

public function __construct($fileName = NULL)
{
$this->_fileName = $fileName ? basename($fileName) : NULL;
}

/**
* Retrieve Raven_Client instance
*
* @return Raven_Client|null
*/
public function getRavenClient()
{
return self::$_ravenClient;
}

/**
* Create Raven_Client instance
* initialize sentry
*
* @return bool
* @throws Raven_Exception
*/
public function initRavenClient()
public function init()
{
if (is_null(self::$_ravenClient)) {
if (!self::$_isInitialized) {
$helper = Mage::helper('firegento_logger');
$dsn = $helper->getLoggerConfig('sentry/public_dsn');
if ( ! $dsn) {
self::$_ravenClient = FALSE;
return FALSE;
if (!$dsn) {
return false;
}
require_once Mage::getBaseDir('lib') . DS . 'sentry' . DS . 'lib' . DS . 'Raven' . DS . 'Autoloader.php';
spl_autoload_register(array('Raven_Autoloader', 'autoload'), true, true);
require_once Mage::getBaseDir('lib') . DS . 'sentry' . DS . 'Autoloader.php';
Sentry_Autoloader::register();

//The options
// "curl_method",
// "trace" do not exist. Defined options are: "attach_stacktrace", "before_breadcrumb", "before_send", "capture_silenced_errors", "class_serializers", "context_lines", "default_integrations", "dsn", "enable_compression", "environment", "error_types", "http_proxy", "in_app_exclude", "in_app_include", "integrations", "logger", "max_breadcrumbs", "max_request_body_size", "max_value_length", "prefixes", "release", "sample_rate", "send_attempts", "send_default_pii", "server_name", "tags", "traces_sample_rate", "traces_sampler".
$options = [
'trace' => $this->_enableBacktrace,
'curl_method' => $helper->getLoggerConfig('sentry/curl_method'),
'dsn' => \Sentry\Dsn::createFromString($dsn),
'attach_stacktrace' => $this->_enableBacktrace,
'prefixes' => [BP],
];
if ($environment = trim($helper->getLoggerConfig('sentry/environment'))) {
$options['environment'] = $environment;
}
self::$_ravenClient = new Raven_Client($dsn, $options);
self::$_ravenClient->setAppPath(dirname(BP));
self::$_ravenClient->trace = TRUE;
$error_handler = new Raven_ErrorHandler(self::$_ravenClient, false);
$error_handler->registerShutdownFunction();
\Sentry\init($options);
self::$_isInitialized = true;
}
return !!self::$_ravenClient;
return self::$_isInitialized;
}

/**
Expand All @@ -114,7 +105,7 @@ protected function _write($event)
try {
Mage::helper('firegento_logger')->addEventMetadata($event, NULL, $this->_enableBacktrace);

if ( ! $this->initRavenClient()) {
if (!$this->init()) {
return;
}

Expand All @@ -137,7 +128,8 @@ protected function _write($event)
],
'extra' => [
'timeElapsed' => $event->getTimeElapsed(),
]
],
'attach_stacktrace' => true
];
if ($event->getAdminUserId()) $data['extra']['adminUserId'] = $event->getAdminUserId();
if ($event->getAdminUserName()) $data['extra']['adminUserName'] = $event->getAdminUserName();
Expand All @@ -152,32 +144,18 @@ protected function _write($event)
}

if ($event->getException()) {
$eventId = self::$_ravenClient->captureException($event->getException(), $data);
$eventId = captureException($event->getException(), EventHint::fromArray($data));
} else {
$data['level'] = $this->_priorityToLevelMapping[$priority];

// Make Raven error handler transparent
$backtrace = $event->getBacktraceArray() ?: TRUE;
if (is_array($backtrace) && count($backtrace) > 3) {
if ( $backtrace[0]['function'] == 'log'
&& $backtrace[1]['function'] == 'mageCoreErrorHandler'
&& isset($backtrace[2]['class'])
&& $backtrace[2]['class'] == 'Raven_Breadcrumbs_ErrorHandler'
) {
array_shift($backtrace);
array_shift($backtrace);
}
}
$level = $this->_priorityToLevelMapping[$priority];

$eventId = self::$_ravenClient->captureMessage(
$eventId = captureMessage(
$event['message'],
[],
$data,
$backtrace
$this->_getSeverityFromLevel($level),
EventHint::fromArray($data)
);
}
Mage::unregister('logger_raven_last_event_id');
Mage::register('logger_raven_last_event_id', $eventId);
Mage::unregister('logger_sentry_last_event_id');
Mage::register('logger_sentry_last_event_id', (string)$eventId);

} catch (Exception $e) {
throw new Zend_Log_Exception($e->getMessage(), $e->getCode());
Expand All @@ -196,18 +174,35 @@ protected function _assumePriorityByMessage(&$event)
stripos($event['message'], "warn") === 0 ||
stripos($event['message'], "user warn") === 0
) {
$event['priority'] = 4;
$event->setPriority(4);
}
else if (
stripos($event['message'], "notice") === 0 ||
stripos($event['message'], "user notice") === 0 ||
stripos($event['message'], "strict notice") === 0 ||
stripos($event['message'], "deprecated") === 0
) {
$event['priority'] = 5;
$event->setPriority(5);
}

return $this;
}

protected function _getSeverityFromLevel(string $level): Severity
{
switch ($level) {
case 'fatal':
return Severity::fatal();
case 'error':
return Severity::error();
case 'warning':
return Severity::warning();
case 'info':
return Severity::info();
case 'debug':
default:
return Severity::debug();
}
}

}

This file was deleted.

13 changes: 0 additions & 13 deletions src/app/code/community/FireGento/Logger/etc/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -794,19 +794,6 @@
(see <a href="https://docs.sentry.io/enriching-error-data/environments/">https://docs.sentry.io/enriching-error-data/environments/</a>).
]]></comment>
</environment>
<curl_method translate="label">
<label>cURL Method</label>
<frontend_type>select</frontend_type>
<source_model>firegento_logger/system_config_source_curlmethods</source_model>
<sort_order>20</sort_order>
<show_in_default>1</show_in_default>
<comment><![CDATA[
Available methods:<br/>
&nbsp;&nbsp;&nbsp;&nbsp;<nobr><strong>sync</strong>: send requests immediately when they’re made</nobr><br/>
&nbsp;&nbsp;&nbsp;&nbsp;<nobr><strong>async</strong> (default): uses a curl_multi handler for best-effort asynchronous submissions</nobr><br/>
&nbsp;&nbsp;&nbsp;&nbsp;<nobr><strong>exec</strong>: asynchronously send events by forking a curl process for each item</nobr>
]]></comment>
</curl_method>
<priority translate="label">
<label>Priority Level Filter</label>
<frontend_type>select</frontend_type>
Expand Down
3 changes: 0 additions & 3 deletions src/lib/sentry/.gitattributes

This file was deleted.

7 changes: 0 additions & 7 deletions src/lib/sentry/.gitignore

This file was deleted.

3 changes: 0 additions & 3 deletions src/lib/sentry/.gitmodules

This file was deleted.

12 changes: 0 additions & 12 deletions src/lib/sentry/.php_cs

This file was deleted.

19 changes: 0 additions & 19 deletions src/lib/sentry/.scrutinizer.yml

This file was deleted.

Loading