forked from paysera/lib-logging-extra-bundle
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSentryExtraInformationHandler.php
More file actions
47 lines (35 loc) · 1.24 KB
/
SentryExtraInformationHandler.php
File metadata and controls
47 lines (35 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
declare(strict_types=1);
namespace Paysera\LoggingExtraBundle\Service\Handler;
use Monolog\Handler\HandlerWrapper;
use Monolog\Handler\ProcessableHandlerTrait;
use Monolog\LogRecord;
use Sentry\State\Scope;
use function Sentry\withScope;
final class SentryExtraInformationHandler extends HandlerWrapper
{
use ProcessableHandlerTrait;
public function handle(LogRecord $record): bool
{
if (!$this->isHandling($record)) {
return false;
}
$result = false;
$record = $this->processRecord($record);
$record['formatted'] = $this->getFormatter()->format($record);
withScope(function (Scope $scope) use ($record, &$result): void {
if (isset($record['context']) && \is_array($record['context'])) {
foreach ($record['context'] as $key => $value) {
$scope->setExtra((string) $key, $value);
}
}
if (isset($record['extra']) && \is_array($record['extra'])) {
foreach ($record['extra'] as $key => $value) {
$scope->setTag($key, (string)$value);
}
}
$result = $this->handler->handle($record);
});
return $result;
}
}