Passed
Pull Request — master (#816)
by butschster
06:28
created

TelemetryProcessor   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 7
dl 0
loc 19
rs 10
c 1
b 0
f 0
ccs 8
cts 8
cp 1

2 Methods

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