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\Logger\ContextExtractor; |
17
|
|
|
|
18
|
|
|
use FRZB\Component\DependencyInjection\Attribute\AsService; |
19
|
|
|
use FRZB\Component\DependencyInjection\Attribute\AsTagged; |
20
|
|
|
use FRZB\Component\MetricsPower\Helper\ClassHelper; |
21
|
|
|
use FRZB\Component\MetricsPower\Helper\MetricalHelper; |
22
|
|
|
use FRZB\Component\MetricsPower\Logger\Data\LoggerContext; |
23
|
|
|
use Symfony\Component\Messenger\Event\SendMessageToTransportsEvent; |
24
|
|
|
use Symfony\Component\Serializer\Encoder\JsonEncoder; |
25
|
|
|
use Symfony\Component\Serializer\SerializerInterface; |
26
|
|
|
|
27
|
|
|
#[AsService, AsTagged(ContextExtractorInterface::class)] |
28
|
|
|
final readonly class SendMessageToTransportsEventContextExtractor implements ContextExtractorInterface |
|
|
|
|
29
|
|
|
{ |
30
|
|
|
private const MESSAGE = '[MetricsPower] [INFO] [MESSAGE: Message sent] [TARGET_CLASS: {target_class}]'; |
31
|
|
|
|
32
|
|
|
public function __construct( |
33
|
|
|
private SerializerInterface $serializer, |
34
|
|
|
) {} |
35
|
|
|
|
36
|
|
|
public function extract(SendMessageToTransportsEvent $target): LoggerContext |
37
|
|
|
{ |
38
|
|
|
$context = [ |
39
|
|
|
'target_class' => ClassHelper::getShortName($target), |
40
|
|
|
'target_values' => $this->serializer->serialize($target, JsonEncoder::FORMAT), |
41
|
|
|
'message_class' => ClassHelper::getShortName($target->getEnvelope()->getMessage()), |
42
|
|
|
]; |
43
|
|
|
|
44
|
|
|
if (($options = MetricalHelper::getFirstOptions($target)) && $options->isSerializable()) { |
45
|
|
|
$context += [ |
46
|
|
|
'options_class' => ClassHelper::getShortName($options), |
47
|
|
|
'options_values' => $this->serializer->serialize($target->getEnvelope()->getMessage(), JsonEncoder::FORMAT), |
48
|
|
|
]; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
return new LoggerContext(self::MESSAGE, $context); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public static function getType(): string |
55
|
|
|
{ |
56
|
|
|
return SendMessageToTransportsEvent::class; |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|