• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

FriendsOfOpenTelemetry / opentelemetry-bundle / 7357653327

29 Dec 2023 02:59PM UTC coverage: 75.594% (-1.7%) from 77.27%
7357653327

push

github

gaelreyrol
feat(Doctrine): start autoinstrumentation

57 of 110 new or added lines in 6 files covered. (51.82%)

3 existing lines in 2 files now uncovered.

1208 of 1598 relevant lines covered (75.59%)

13.62 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/EventSubscriber/ConsoleMetricEventSubscriber.php
1
<?php
2

3
namespace FriendsOfOpenTelemetry\OpenTelemetryBundle\EventSubscriber;
4

5
use OpenTelemetry\API\Metrics\CounterInterface;
6
use OpenTelemetry\API\Metrics\MeterInterface;
7
use OpenTelemetry\SDK\Metrics\MeterProviderInterface;
8
use Symfony\Component\Console\Command\Command;
9
use Symfony\Component\Console\ConsoleEvents;
10
use Symfony\Component\Console\Event\ConsoleCommandEvent;
11
use Symfony\Component\Console\Event\ConsoleErrorEvent;
12
use Symfony\Component\Console\Event\ConsoleSignalEvent;
13
use Symfony\Component\Console\Event\ConsoleTerminateEvent;
14
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
15

16
final class ConsoleMetricEventSubscriber implements EventSubscriberInterface
17
{
18
    private CounterInterface $totalCommandsCounter;
19
    private CounterInterface $commandCounter;
20

21
    public function __construct(
22
        private readonly MeterInterface $meter,
23
        private readonly MeterProviderInterface $meterProvider,
24
    ) {
NEW
25
        $this->totalCommandsCounter = $this->meter->createCounter('symfony_console_commands');
×
NEW
26
        $this->commandCounter = $this->meter->createCounter('symfony_console_command');
×
27
    }
28

29
    public static function getSubscribedEvents(): array
30
    {
31
        return [
×
32
            ConsoleEvents::COMMAND => [
×
33
                ['recordCommand', 10000],
×
34
            ],
×
35
            ConsoleEvents::ERROR => [
×
36
                ['recordError', -10000],
×
37
            ],
×
38
            ConsoleEvents::TERMINATE => [
×
39
                ['recordStatus', -10000],
×
NEW
40
                ['flushMeterProvider', -20000],
×
41
            ],
×
42
            ConsoleEvents::SIGNAL => [
×
43
                ['recordSignal', -10000],
×
44
            ],
×
45
        ];
×
46
    }
47

48
    public function recordCommand(ConsoleCommandEvent $event): void
49
    {
NEW
50
        $this->totalCommandsCounter->add(1);
×
51

UNCOV
52
        $command = $event->getCommand();
×
53

54
        assert($command instanceof Command);
55

56
        $name = $command->getName();
×
57
        $class = get_class($command);
×
58

NEW
59
        $this->commandCounter->add(1, [
×
NEW
60
            'name' => $name,
×
NEW
61
            'class' => $class,
×
NEW
62
        ]);
×
63
    }
64

65
    public function recordError(ConsoleErrorEvent $event): void
66
    {
67
    }
×
68

69
    public function recordStatus(ConsoleTerminateEvent $event): void
70
    {
71
    }
×
72

73
    public function recordSignal(ConsoleSignalEvent $event): void
74
    {
75
    }
×
76

77
    public function flushMeterProvider(ConsoleTerminateEvent $event): void
78
    {
NEW
79
        $this->meterProvider->forceFlush();
×
80
    }
81
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc