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

TelemetryProcessor::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 0
c 0
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
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