1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Tolerance package. |
5
|
|
|
* |
6
|
|
|
* (c) Samuel ROZE <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Tolerance\Bridge\RabbitMqBundle\Tracer; |
13
|
|
|
|
14
|
|
|
use OldSound\RabbitMqBundle\RabbitMq\ConsumerInterface; |
15
|
|
|
use PhpAmqpLib\Message\AMQPMessage; |
16
|
|
|
use Tolerance\Tracer\SpanFactory\Amqp\AmqpSpanFactory; |
17
|
|
|
use Tolerance\Tracer\SpanStack\SpanStack; |
18
|
|
|
use Tolerance\Tracer\Tracer; |
19
|
|
|
|
20
|
|
|
final class TracedConsumer implements ConsumerInterface |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @var ConsumerInterface |
24
|
|
|
*/ |
25
|
|
|
private $decoratedConsumer; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var Tracer |
29
|
|
|
*/ |
30
|
|
|
private $tracer; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var SpanStack |
34
|
|
|
*/ |
35
|
|
|
private $spanStack; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var AmqpSpanFactory |
39
|
|
|
*/ |
40
|
|
|
private $amqpSpanFactory; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @param ConsumerInterface $decoratedConsumer |
44
|
|
|
* @param Tracer $tracer |
45
|
|
|
* @param SpanStack $spanStack |
46
|
|
|
* @param AmqpSpanFactory $amqpSpanFactory |
47
|
|
|
*/ |
48
|
|
|
public function __construct(ConsumerInterface $decoratedConsumer, Tracer $tracer, SpanStack $spanStack, AmqpSpanFactory $amqpSpanFactory) |
49
|
|
|
{ |
50
|
|
|
$this->decoratedConsumer = $decoratedConsumer; |
51
|
|
|
$this->tracer = $tracer; |
52
|
|
|
$this->spanStack = $spanStack; |
53
|
|
|
$this->amqpSpanFactory = $amqpSpanFactory; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* {@inheritdoc} |
58
|
|
|
*/ |
59
|
|
|
public function execute(AMQPMessage $msg) |
60
|
|
|
{ |
61
|
|
|
$span = $this->amqpSpanFactory->fromReceivedMessage($msg); |
62
|
|
|
|
63
|
|
|
$this->tracer->trace([$span]); |
64
|
|
|
|
65
|
|
|
$this->spanStack->push($span); |
66
|
|
|
|
67
|
|
|
$result = $this->decoratedConsumer->execute($msg); |
68
|
|
|
|
69
|
|
|
$this->tracer->trace([ |
70
|
|
|
$this->amqpSpanFactory->fromConsumedMessage($msg), |
71
|
|
|
]); |
72
|
|
|
|
73
|
|
|
$this->spanStack->pop(); |
74
|
|
|
|
75
|
|
|
return $result; |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|