Passed
Push — master ( dcb61c...e80a85 )
by butschster
05:46 queued 18s
created

TelemetryProcessor   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 90.91%

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 4
eloc 9
c 4
b 0
f 0
dl 0
loc 23
ccs 10
cts 11
cp 0.9091
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A __invoke() 0 16 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Spiral\Telemetry\Monolog;
6
7
use Monolog\LogRecord;
8
use Monolog\Processor\ProcessorInterface;
9
use Psr\Container\ContainerInterface;
10
use Spiral\Telemetry\TracerInterface;
11
12
final class TelemetryProcessor implements ProcessorInterface
13
{
14 2
    public function __construct(
15
        private readonly ContainerInterface $container
16
    ) {
17 2
    }
18
19 2
    public function __invoke(LogRecord|array $record): array
20
    {
21 2
        if ($record instanceof LogRecord) {
0 ignored issues
show
introduced by
$record is never a sub-type of Monolog\LogRecord.
Loading history...
22
            $record = $record->toArray();
23
        }
24
25 2
        $tracer = $this->container->get(TracerInterface::class);
26 2
        \assert($tracer instanceof TracerInterface);
27
28 2
        $context = $tracer->getContext();
29
30 2
        if (!empty($context)) {
31 1
            $record['extra']['telemetry'] = $context;
32
        }
33
34 2
        return $record;
35
    }
36
}
37