#php #xdebug #sentry #monolog
#php #xdebug #sentry #monolog
Вопрос:
В настоящее время у меня настроено 2 обработчика Monolog. Один перенаправляет ошибки / исключения на stderr
, а другой отправляет их в Sentry.
$pimple[Logger::class] = function (ContainerInterface $container): Logger {
$monologLogger = new Logger('logger');
#Stream Logs to stderr
$streamHandler = new StreamHandler('php://stderr');
#Send Logs to Sentry
Sentryinit(
[
'dsn' => 'http://key@url/project_id',
'default_integrations' => false
]);
$sentryHandler = new Handler(SentrySdk::getCurrentHub(), Logger::NOTICE);
$jsonFormatter = new JsonFormatter();
$streamHandler->setFormatter($jsonFormatter);
$sentryHandler->setFormatter($jsonFormatter);
$monologLogger->pushProcessor(function ($record) {
if (isset($record['context']['error']) amp;amp; is_array($record['context'])) {
foreach ($record['context'] as $key => $value) {
if ($key === 'tags') {
//Handled natively by Sentry monolog handler
continue;
}
$record['context']['extra'][$key] = is_string($value) amp;amp; json_decode($value) !== null ? json_decode($value) : $value;
}
}
return $record;
});
$monologLogger->pushHandler($streamHandler);
$monologLogger->pushHandler($sentryHandler);
return $monologLogger;
};
Моя проблема в том, что при просмотре stderr контекст ошибки выглядит следующим образом, и это именно то, что я хочу, чтобы он выглядел, потому что он точно сообщает мне, что мне нужно знать, чтобы идентифицировать ошибку.
"error":{"class":"Error","message":"Call to undefined function Presentation\Web\Action\Nodes\div()","code":0,"file":"/Presentation/Web/Action/Nodes/GetNodesAction.php:19"}
Но именно так они отображаются в Sentry, что очень затрудняет его правильное чтение.
"error":{ xdebug_message:
<tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Error: Call to undefined function PresentationWebActionNodesdiv() in /Presentation/Web/Action/Nodes/GetNodesAction.php on line <i>19</i></th></tr>
<tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr>
<tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left' bgcolor='#eeeeec'>Time</th><th align='left' bgcolor='#eeeeec'>Memory</th><th align='left' bgcolor='#eeeeec'>Function</th><th align='left' bgcolor='#eeeeec'>Location</th></tr>
<tr><td bgcolor='#eeeeec' align='center'>1</td><td bgcolor='#eeeeec' align='center'>0.0009</td><td bgcolor='#eeeeec' align='right'>471848</td><td bgcolor='#eeeeec'>{main}( )</td><td title='/app/test/web/index.php' bgcolor='#eeeeec'>.../index.php<b>:</b>0</td></tr>
<tr><td bgcolor='#eeeeec' align='center'>2</td><td bgcolor='#eeeeec' align='center'>0.0060</td><td bgcolor='#eeeeec' align='right'>472120</td><td bgcolor='#eeeeec'>require( <font color='#00bb00'>'/app/web/index.php'</font> )</td><td title='/app/test/web/index.php' bgcolor='#eeeeec'>.../index.php<b>:</b>14</td></tr>
<tr><td bgcolor='#eeeeec' align='center'>3</td><td bgcolor='#eeeeec' align='center'>0.6470</td><td bgcolor='#eeeeec' align='right'>1460136</td><td bgcolor='#eeeeec'>SlimApp->run( )</td><td title='/app/web/index.php' bgcolor='#eeeeec'>.../index.php<b>:</b>9</td></tr>
<tr><td bgcolor='#eeeeec' align='center'>4</td><td bgcolor='#eeeeec' align='center'>0.7036</td><td bgcolor='#eeeeec' align='right'>1609552</td><td bgcolor='#eeeeec'>SlimApp->process( )</td><td title='/app/vendor/slim/slim/Slim/App.php' bgcolor='#eeeeec'>.../App.php<b>:</b>297</td></tr>
<tr><td bgcolor='#eeeeec' align='center'>5</td><td bgcolor='#eeeeec' align='center'>0.7511</td><td bgcolor='#eeeeec' align='right'>1740704</td><td bgcolor='#eeeeec'>SlimApp->callMiddlewareStack( )</td><td title='/app/vendor/slim/slim/Slim/App.php' bgcolor='#eeeeec'>.../App.php<b>:</b>392</td></tr>
<tr><td bgcolor='#eeeeec' align='center'>6</td><td bgcolor='#eeeeec' align='center'>0.7511</td><td bgcolor='#eeeeec' align='right'>1740704</td><td bgcolor='#eeeeec'>SlimApp->Slim{closure:/app/vendor/slim/slim/Slim/MiddlewareAwareTrait.php:63-78}( )</td><td title='/app/vendor/slim/slim/Slim/MiddlewareAwareTrait.php' bgcolor='#eeeeec'>.../MiddlewareAwareTrait.php<b>:</b>117</td></tr>
... rest of the output omitted ...
Есть ли у кого-нибудь идеи, как я могу убедиться, что объект не изменится?