Passed
Pull Request — master (#1193)
by butschster
17:21 queued 06:12
created

TelemetryProcessor::__invoke()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 6
c 3
b 0
f 0
dl 0
loc 12
ccs 7
cts 7
cp 1
rs 10
cc 2
nc 2
nop 1
crap 2
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 4
    public function __construct(
15
        private readonly ContainerInterface $container,
16 4
    ) {}
17
18
    /**
19
     * @psalm-suppress InvalidReturnType
20
     * @psalm-suppress InvalidReturnStatement
21
     */
22 4
    public function __invoke(LogRecord|array $record): array|LogRecord
23
    {
24 4
        $tracer = $this->container->get(TracerInterface::class);
25 4
        \assert($tracer instanceof TracerInterface);
26
27 4
        $context = $tracer->getContext();
28
29 4
        if (!empty($context)) {
30 2
            $record['extra']['telemetry'] = $context;
31
        }
32
33 4
        return $record;
34
    }
35
}
36