1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
7
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
8
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
9
|
|
|
* |
10
|
|
|
* Copyright (c) 2024 Mykhailo Shtanko [email protected] |
11
|
|
|
* |
12
|
|
|
* For the full copyright and license information, please view the LICENSE.MD |
13
|
|
|
* file that was distributed with this source code. |
14
|
|
|
*/ |
15
|
|
|
|
16
|
|
|
namespace FRZB\Component\MetricsPower\OptionsResolver\Resolver; |
17
|
|
|
|
18
|
|
|
use FRZB\Component\DependencyInjection\Attribute\AsService; |
19
|
|
|
use FRZB\Component\DependencyInjection\Attribute\AsTagged; |
20
|
|
|
use FRZB\Component\MetricsPower\Attribute\SentryOptions; |
21
|
|
|
use Sentry\State\HubInterface; |
22
|
|
|
use Symfony\Component\Messenger\Event\AbstractWorkerMessageEvent; |
23
|
|
|
use Symfony\Component\Messenger\Event\SendMessageToTransportsEvent; |
24
|
|
|
use Symfony\Component\Messenger\Event\WorkerMessageFailedEvent; |
25
|
|
|
use Symfony\Component\Messenger\Event\WorkerMessageHandledEvent; |
26
|
|
|
|
27
|
|
|
#[AsService, AsTagged(OptionsResolverInterface::class)] |
28
|
|
|
class SentryOptionsResolver implements OptionsResolverInterface |
29
|
|
|
{ |
30
|
|
|
public function __construct( |
31
|
|
|
private readonly HubInterface $hub |
32
|
|
|
) {} |
33
|
|
|
|
34
|
|
|
public function __invoke(AbstractWorkerMessageEvent|SendMessageToTransportsEvent $event, SentryOptions $options): void |
35
|
|
|
{ |
36
|
|
|
match ($event::class) { |
37
|
|
|
WorkerMessageFailedEvent::class => $this->onWorkerMessageFailedEvent($event, $options), |
|
|
|
|
38
|
|
|
WorkerMessageHandledEvent::class => $this->onWorkerMessageHandledEvent($event, $options), |
|
|
|
|
39
|
|
|
default => null, |
40
|
|
|
}; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public static function getType(): string |
44
|
|
|
{ |
45
|
|
|
return SentryOptions::class; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
private function onWorkerMessageFailedEvent(WorkerMessageFailedEvent $event, SentryOptions $options): void |
49
|
|
|
{ |
50
|
|
|
if ($event->willRetry() && $options->waitRetry) { |
51
|
|
|
return; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
$this->hub->captureException($event->getThrowable()); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
private function onWorkerMessageHandledEvent(WorkerMessageHandledEvent $event, SentryOptions $options): void |
|
|
|
|
58
|
|
|
{ |
59
|
|
|
$options->onHandleFlush && $this->hub->getClient()?->flush(); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|