From 018e7fd2c3039fb43bc004b9a8efd033907330d8 Mon Sep 17 00:00:00 2001 From: Richard Chukwu Date: Fri, 11 Oct 2024 15:36:52 +0100 Subject: [PATCH 1/9] Update Symfony Messenger instrumentation to use SpanKind::KIND_PRODUCER and KIND_CONSUMER --- src/Instrumentation/Symfony/src/MessengerInstrumentation.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Instrumentation/Symfony/src/MessengerInstrumentation.php b/src/Instrumentation/Symfony/src/MessengerInstrumentation.php index 6fbdcc2c..1a3f9b0f 100644 --- a/src/Instrumentation/Symfony/src/MessengerInstrumentation.php +++ b/src/Instrumentation/Symfony/src/MessengerInstrumentation.php @@ -58,7 +58,7 @@ public static function register(): void $builder = $instrumentation ->tracer() ->spanBuilder(\sprintf('DISPATCH %s', $messageClass)) - ->setSpanKind(SpanKind::KIND_INTERNAL) + ->setSpanKind(SpanKind::KIND_PRODUCER) ->setAttribute(TraceAttributes::CODE_FUNCTION, $function) ->setAttribute(TraceAttributes::CODE_NAMESPACE, $class) ->setAttribute(TraceAttributes::CODE_FILEPATH, $filename) @@ -125,7 +125,7 @@ public static function register(): void $builder = $instrumentation ->tracer() ->spanBuilder(\sprintf('SEND %s', $messageClass)) - ->setSpanKind(SpanKind::KIND_INTERNAL) + ->setSpanKind(SpanKind::KIND_CONSUMER) ->setAttribute(TraceAttributes::CODE_FUNCTION, $function) ->setAttribute(TraceAttributes::CODE_NAMESPACE, $class) ->setAttribute(TraceAttributes::CODE_FILEPATH, $filename) From 66fa258767f8cef7f0a33e796e5487e507bbec06 Mon Sep 17 00:00:00 2001 From: Richard Chukwu Date: Fri, 11 Oct 2024 16:40:59 +0100 Subject: [PATCH 2/9] test file edit to match instrumentation --- .../tests/Integration/MessengerInstrumentationTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Instrumentation/Symfony/tests/Integration/MessengerInstrumentationTest.php b/src/Instrumentation/Symfony/tests/Integration/MessengerInstrumentationTest.php index 8f0cff15..bf3242bd 100644 --- a/src/Instrumentation/Symfony/tests/Integration/MessengerInstrumentationTest.php +++ b/src/Instrumentation/Symfony/tests/Integration/MessengerInstrumentationTest.php @@ -157,7 +157,7 @@ public function sendDataProvider(): array [ new SendEmailMessage('Hello Again'), 'SEND OpenTelemetry\Tests\Instrumentation\Symfony\tests\Integration\SendEmailMessage', - SpanKind::KIND_INTERNAL, + SpanKind::KIND_CONSUMER, [ MessengerInstrumentation::ATTRIBUTE_MESSENGER_TRANSPORT => class_exists('Symfony\Component\Messenger\Transport\InMemory\InMemoryTransport') ? 'Symfony\Component\Messenger\Transport\InMemory\InMemoryTransport' : 'Symfony\Component\Messenger\Transport\InMemoryTransport', MessengerInstrumentation::ATTRIBUTE_MESSENGER_MESSAGE => 'OpenTelemetry\Tests\Instrumentation\Symfony\tests\Integration\SendEmailMessage', @@ -172,7 +172,7 @@ public function dispatchDataProvider(): array [ new SendEmailMessage('Hello Again'), 'DISPATCH OpenTelemetry\Tests\Instrumentation\Symfony\tests\Integration\SendEmailMessage', - SpanKind::KIND_INTERNAL, + SpanKind::KIND_PRODUCER, [ MessengerInstrumentation::ATTRIBUTE_MESSENGER_BUS => 'Symfony\Component\Messenger\MessageBus', MessengerInstrumentation::ATTRIBUTE_MESSENGER_MESSAGE => 'OpenTelemetry\Tests\Instrumentation\Symfony\tests\Integration\SendEmailMessage', From bdbb36f6cb4c5df8130728ebd984399a867c0a4f Mon Sep 17 00:00:00 2001 From: Richard Chukwu <79311274+RichardChukwu@users.noreply.github.com> Date: Tue, 15 Oct 2024 23:49:52 +0100 Subject: [PATCH 3/9] Send instrumentation updated to KIND_PRODUCER --- src/Instrumentation/Symfony/src/MessengerInstrumentation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Instrumentation/Symfony/src/MessengerInstrumentation.php b/src/Instrumentation/Symfony/src/MessengerInstrumentation.php index 1a3f9b0f..9b0b8e60 100644 --- a/src/Instrumentation/Symfony/src/MessengerInstrumentation.php +++ b/src/Instrumentation/Symfony/src/MessengerInstrumentation.php @@ -125,7 +125,7 @@ public static function register(): void $builder = $instrumentation ->tracer() ->spanBuilder(\sprintf('SEND %s', $messageClass)) - ->setSpanKind(SpanKind::KIND_CONSUMER) + ->setSpanKind(SpanKind::KIND_PRODUCER) ->setAttribute(TraceAttributes::CODE_FUNCTION, $function) ->setAttribute(TraceAttributes::CODE_NAMESPACE, $class) ->setAttribute(TraceAttributes::CODE_FILEPATH, $filename) From 730c424b9f4e90694ec46645c12abc93cfb9e5d1 Mon Sep 17 00:00:00 2001 From: Richard Chukwu Date: Wed, 16 Oct 2024 00:12:57 +0100 Subject: [PATCH 4/9] Test updated --- src/Instrumentation/Symfony/src/MessengerInstrumentation.php | 2 +- .../Symfony/tests/Integration/MessengerInstrumentationTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Instrumentation/Symfony/src/MessengerInstrumentation.php b/src/Instrumentation/Symfony/src/MessengerInstrumentation.php index 1a3f9b0f..9b0b8e60 100644 --- a/src/Instrumentation/Symfony/src/MessengerInstrumentation.php +++ b/src/Instrumentation/Symfony/src/MessengerInstrumentation.php @@ -125,7 +125,7 @@ public static function register(): void $builder = $instrumentation ->tracer() ->spanBuilder(\sprintf('SEND %s', $messageClass)) - ->setSpanKind(SpanKind::KIND_CONSUMER) + ->setSpanKind(SpanKind::KIND_PRODUCER) ->setAttribute(TraceAttributes::CODE_FUNCTION, $function) ->setAttribute(TraceAttributes::CODE_NAMESPACE, $class) ->setAttribute(TraceAttributes::CODE_FILEPATH, $filename) diff --git a/src/Instrumentation/Symfony/tests/Integration/MessengerInstrumentationTest.php b/src/Instrumentation/Symfony/tests/Integration/MessengerInstrumentationTest.php index bf3242bd..63d38849 100644 --- a/src/Instrumentation/Symfony/tests/Integration/MessengerInstrumentationTest.php +++ b/src/Instrumentation/Symfony/tests/Integration/MessengerInstrumentationTest.php @@ -157,7 +157,7 @@ public function sendDataProvider(): array [ new SendEmailMessage('Hello Again'), 'SEND OpenTelemetry\Tests\Instrumentation\Symfony\tests\Integration\SendEmailMessage', - SpanKind::KIND_CONSUMER, + SpanKind::KIND_PRODUCER, [ MessengerInstrumentation::ATTRIBUTE_MESSENGER_TRANSPORT => class_exists('Symfony\Component\Messenger\Transport\InMemory\InMemoryTransport') ? 'Symfony\Component\Messenger\Transport\InMemory\InMemoryTransport' : 'Symfony\Component\Messenger\Transport\InMemoryTransport', MessengerInstrumentation::ATTRIBUTE_MESSENGER_MESSAGE => 'OpenTelemetry\Tests\Instrumentation\Symfony\tests\Integration\SendEmailMessage', From ea5f1b1465b2a2cb5af452ada9a6fdf4bfb198e1 Mon Sep 17 00:00:00 2001 From: Richard Chukwu Date: Thu, 17 Oct 2024 11:18:52 +0100 Subject: [PATCH 5/9] Message receive (KIND_CONSUMER) instrumentation updated --- composer.json | 3 +- .../Symfony/src/MessengerInstrumentation.php | 97 +++++++++++++++---- .../MessengerInstrumentationTest.php | 58 ++++++++++- 3 files changed, 135 insertions(+), 23 deletions(-) diff --git a/composer.json b/composer.json index 7ac30bc1..b8936b9e 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,8 @@ }, "require-dev": { "composer/xdebug-handler": "^2.0", - "open-telemetry/dev-tools": "dev-main" + "open-telemetry/dev-tools": "dev-main", + "phpunit/phpunit": "^11.4" }, "autoload": { "psr-4": { diff --git a/src/Instrumentation/Symfony/src/MessengerInstrumentation.php b/src/Instrumentation/Symfony/src/MessengerInstrumentation.php index 9b0b8e60..ccdae7b4 100644 --- a/src/Instrumentation/Symfony/src/MessengerInstrumentation.php +++ b/src/Instrumentation/Symfony/src/MessengerInstrumentation.php @@ -36,10 +36,9 @@ public static function register(): void { $instrumentation = new CachedInstrumentation('io.opentelemetry.contrib.php.symfony_messenger'); - /** - * MessageBusInterface dispatches messages to the handlers. - */ - hook( + + // Instrument MessageBusInterface (message dispatching) + hook( MessageBusInterface::class, 'dispatch', pre: static function ( @@ -54,19 +53,17 @@ public static function register(): void $message = $params[0]; $messageClass = \get_class($message); - /** @psalm-suppress ArgumentTypeCoercion */ + // Instrument dispatch as a "send" operation with SpanKind::KIND_PRODUCER $builder = $instrumentation ->tracer() - ->spanBuilder(\sprintf('DISPATCH %s', $messageClass)) - ->setSpanKind(SpanKind::KIND_PRODUCER) + ->spanBuilder(\sprintf('publish %s', $messageClass)) + ->setSpanKind(SpanKind::KIND_PRODUCER) // Set KIND_PRODUCER for dispatch ->setAttribute(TraceAttributes::CODE_FUNCTION, $function) ->setAttribute(TraceAttributes::CODE_NAMESPACE, $class) ->setAttribute(TraceAttributes::CODE_FILEPATH, $filename) ->setAttribute(TraceAttributes::CODE_LINENO, $lineno) - ->setAttribute(self::ATTRIBUTE_MESSENGER_BUS, $class) - ->setAttribute(self::ATTRIBUTE_MESSENGER_MESSAGE, $messageClass) - ; + ->setAttribute(self::ATTRIBUTE_MESSENGER_MESSAGE, $messageClass); $parent = Context::getCurrent(); $span = $builder @@ -103,9 +100,7 @@ public static function register(): void } ); - /** - * SenderInterface sends messages to a transport. - */ + // Instrument SenderInterface (sending messages to transport) hook( SenderInterface::class, 'send', @@ -121,28 +116,88 @@ public static function register(): void $envelope = $params[0]; $messageClass = \get_class($envelope->getMessage()); - /** @psalm-suppress ArgumentTypeCoercion */ + // Instrument sending as a "send" operation with SpanKind::KIND_PRODUCER + $builder = $instrumentation + ->tracer() + ->spanBuilder(\sprintf('send %s', $messageClass)) + ->setSpanKind(SpanKind::KIND_PRODUCER) // Set KIND_PRODUCER for sending + ->setAttribute(TraceAttributes::CODE_FUNCTION, $function) + ->setAttribute(TraceAttributes::CODE_NAMESPACE, $class) + ->setAttribute(TraceAttributes::CODE_FILEPATH, $filename) + ->setAttribute(TraceAttributes::CODE_LINENO, $lineno) + ->setAttribute(self::ATTRIBUTE_MESSENGER_TRANSPORT, $class) + ->setAttribute(self::ATTRIBUTE_MESSENGER_MESSAGE, $messageClass); + + $parent = Context::getCurrent(); + $span = $builder + ->setParent($parent) + ->startSpan(); + + $context = $span->storeInContext($parent); + + Context::storage()->attach($context); + + return $params; + }, + post: static function ( + SenderInterface $sender, + array $params, + ?Envelope $result, + ?\Throwable $exception + ): void { + $scope = Context::storage()->scope(); + if (null === $scope) { + return; + } + + $scope->detach(); + $span = Span::fromContext($scope->context()); + + if (null !== $exception) { + $span->recordException($exception, [ + TraceAttributes::EXCEPTION_ESCAPED => true, + ]); + $span->setStatus(StatusCode::STATUS_ERROR, $exception->getMessage()); + } + + $span->end(); + } + ); + + // Instrument the receiving of messages (consumer-side) + hook( + SenderInterface::class, + 'receive', + pre: static function ( + SenderInterface $bus, + array $params, + string $class, + string $function, + ?string $filename, + ?int $lineno, + ) use ($instrumentation): array { + /** @var Envelope $envelope */ + $envelope = $params[0]; + $messageClass = \get_class($envelope->getMessage()); + + // Instrument receiving as a "consume" operation with SpanKind::KIND_CONSUMER $builder = $instrumentation ->tracer() - ->spanBuilder(\sprintf('SEND %s', $messageClass)) - ->setSpanKind(SpanKind::KIND_PRODUCER) + ->spanBuilder(\sprintf('consume %s', $messageClass)) + ->setSpanKind(SpanKind::KIND_CONSUMER) // Set KIND_CONSUMER for receiving ->setAttribute(TraceAttributes::CODE_FUNCTION, $function) ->setAttribute(TraceAttributes::CODE_NAMESPACE, $class) ->setAttribute(TraceAttributes::CODE_FILEPATH, $filename) ->setAttribute(TraceAttributes::CODE_LINENO, $lineno) - ->setAttribute(self::ATTRIBUTE_MESSENGER_TRANSPORT, $class) - ->setAttribute(self::ATTRIBUTE_MESSENGER_MESSAGE, $messageClass) - ; + ->setAttribute(self::ATTRIBUTE_MESSENGER_MESSAGE, $messageClass); $parent = Context::getCurrent(); - $span = $builder ->setParent($parent) ->startSpan(); $context = $span->storeInContext($parent); - Context::storage()->attach($context); return $params; diff --git a/src/Instrumentation/Symfony/tests/Integration/MessengerInstrumentationTest.php b/src/Instrumentation/Symfony/tests/Integration/MessengerInstrumentationTest.php index 63d38849..347a88de 100644 --- a/src/Instrumentation/Symfony/tests/Integration/MessengerInstrumentationTest.php +++ b/src/Instrumentation/Symfony/tests/Integration/MessengerInstrumentationTest.php @@ -35,6 +35,7 @@ protected function getMessenger(): MessageBusInterface { return new MessageBus(); } + protected function getTransport() { // Symfony 6+ @@ -56,7 +57,6 @@ protected function getTransport() public function test_dispatch_message($message, string $spanName, int $kind, array $attributes) { $bus = $this->getMessenger(); - $bus->dispatch($message); $this->assertCount(1, $this->storage); @@ -99,6 +99,62 @@ public function test_send_message($message, string $spanName, int $kind, array $ } } + /** + * Test consumer span when processing a message + */ + public function test_consume_message() + { + $transport = $this->getTransport(); + $message = new SendEmailMessage('Hello Consumer'); + $envelope = new Envelope($message); + + // Simulate receiving the message via the transport + $transport->send($envelope); + + // Simulate message consumption (processing) + $bus = $this->getMessenger(); + $bus->dispatch($message); + + // After message is consumed, we expect a consumer span + $this->assertCount(1, $this->storage); + + /** @var ImmutableSpan $span */ + $span = $this->storage[0]; + + // We expect this to be a consumer span + $this->assertEquals('CONSUME OpenTelemetry\Tests\Instrumentation\Symfony\tests\Integration\SendEmailMessage', $span->getName()); + $this->assertEquals(SpanKind::KIND_CONSUMER, $span->getKind()); + + $this->assertTrue($span->getAttributes()->has(MessengerInstrumentation::ATTRIBUTE_MESSENGER_MESSAGE)); + $this->assertEquals('OpenTelemetry\Tests\Instrumentation\Symfony\tests\Integration\SendEmailMessage', $span->getAttributes()->get(MessengerInstrumentation::ATTRIBUTE_MESSENGER_MESSAGE)); + } + + /** + * @dataProvider sendDataProvider + * @param mixed $message + * @param string $spanName + * @param int $kind + * @param array $attributes + */ + public function test_send_message($message, string $spanName, int $kind, array $attributes) + { + $transport = $this->getTransport(); + $transport->send(new Envelope($message)); + + $this->assertCount(1, $this->storage); + + /** @var ImmutableSpan $span */ + $span = $this->storage[0]; + + $this->assertEquals($spanName, $span->getName()); + $this->assertEquals($kind, $span->getKind()); + + foreach ($attributes as $key => $value) { + $this->assertTrue($span->getAttributes()->has($key), sprintf('Attribute %s not found', $key)); + $this->assertEquals($value, $span->getAttributes()->get($key)); + } + } + public function test_can_sustain_throw_while_dispatching() { $bus = new class() implements MessageBusInterface { From 3e46678b02ec618775dbe71659d49010bd3f143f Mon Sep 17 00:00:00 2001 From: Richard Chukwu Date: Thu, 17 Oct 2024 11:43:18 +0100 Subject: [PATCH 6/9] error fix --- src/Instrumentation/Symfony/src/MessengerInstrumentation.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/Instrumentation/Symfony/src/MessengerInstrumentation.php b/src/Instrumentation/Symfony/src/MessengerInstrumentation.php index 854b329e..2798e49f 100644 --- a/src/Instrumentation/Symfony/src/MessengerInstrumentation.php +++ b/src/Instrumentation/Symfony/src/MessengerInstrumentation.php @@ -56,13 +56,8 @@ public static function register(): void // Instrument dispatch as a "send" operation with SpanKind::KIND_PRODUCER $builder = $instrumentation ->tracer() -<<<<<<< HEAD ->spanBuilder(\sprintf('publish %s', $messageClass)) ->setSpanKind(SpanKind::KIND_PRODUCER) // Set KIND_PRODUCER for dispatch -======= - ->spanBuilder(\sprintf('DISPATCH %s', $messageClass)) - ->setSpanKind(SpanKind::KIND_PRODUCER) ->>>>>>> 78a04cebaeba48d60a00dc1c48653695b926299d ->setAttribute(TraceAttributes::CODE_FUNCTION, $function) ->setAttribute(TraceAttributes::CODE_NAMESPACE, $class) ->setAttribute(TraceAttributes::CODE_FILEPATH, $filename) From da0cf7b698dbcd5582d1c19a8b2afa5dc724418e Mon Sep 17 00:00:00 2001 From: Richard Chukwu Date: Thu, 17 Oct 2024 22:27:34 +0100 Subject: [PATCH 7/9] Relax PHP requirement for phpunit to support PHP 8.0 and 8.1 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index b8936b9e..214c3baf 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ "require-dev": { "composer/xdebug-handler": "^2.0", "open-telemetry/dev-tools": "dev-main", - "phpunit/phpunit": "^11.4" + "phpunit/phpunit": "^8.0 || ^9.5 || ^10.0" // Support for PHP 8.0/8.1 while allowing newer versions }, "autoload": { "psr-4": { From 8204d403e826cb2eeec66a853fed39d6d3e3e3db Mon Sep 17 00:00:00 2001 From: Richard Chukwu Date: Thu, 17 Oct 2024 22:28:28 +0100 Subject: [PATCH 8/9] Correct spec update --- .../Symfony/src/MessengerInstrumentation.php | 20 ++----- .../MessengerInstrumentationTest.php | 53 +++++++------------ 2 files changed, 22 insertions(+), 51 deletions(-) diff --git a/src/Instrumentation/Symfony/src/MessengerInstrumentation.php b/src/Instrumentation/Symfony/src/MessengerInstrumentation.php index 2798e49f..a3d37444 100644 --- a/src/Instrumentation/Symfony/src/MessengerInstrumentation.php +++ b/src/Instrumentation/Symfony/src/MessengerInstrumentation.php @@ -118,7 +118,6 @@ public static function register(): void // Instrument sending as a "send" operation with SpanKind::KIND_PRODUCER $builder = $instrumentation -<<<<<<< HEAD ->tracer() ->spanBuilder(\sprintf('send %s', $messageClass)) ->setSpanKind(SpanKind::KIND_PRODUCER) // Set KIND_PRODUCER for sending @@ -128,19 +127,6 @@ public static function register(): void ->setAttribute(TraceAttributes::CODE_LINENO, $lineno) ->setAttribute(self::ATTRIBUTE_MESSENGER_TRANSPORT, $class) ->setAttribute(self::ATTRIBUTE_MESSENGER_MESSAGE, $messageClass); -======= - ->tracer() - ->spanBuilder(\sprintf('SEND %s', $messageClass)) - ->setSpanKind(SpanKind::KIND_PRODUCER) - ->setAttribute(TraceAttributes::CODE_FUNCTION, $function) - ->setAttribute(TraceAttributes::CODE_NAMESPACE, $class) - ->setAttribute(TraceAttributes::CODE_FILEPATH, $filename) - ->setAttribute(TraceAttributes::CODE_LINENO, $lineno) - - ->setAttribute(self::ATTRIBUTE_MESSENGER_TRANSPORT, $class) - ->setAttribute(self::ATTRIBUTE_MESSENGER_MESSAGE, $messageClass) - ; ->>>>>>> 78a04cebaeba48d60a00dc1c48653695b926299d $parent = Context::getCurrent(); $span = $builder @@ -180,9 +166,9 @@ public static function register(): void // Instrument the receiving of messages (consumer-side) hook( - SenderInterface::class, - 'receive', - pre: static function ( + ReceiverInterface::class, + 'get', + static function ( SenderInterface $bus, array $params, string $class, diff --git a/src/Instrumentation/Symfony/tests/Integration/MessengerInstrumentationTest.php b/src/Instrumentation/Symfony/tests/Integration/MessengerInstrumentationTest.php index 347a88de..5c7cbfbc 100644 --- a/src/Instrumentation/Symfony/tests/Integration/MessengerInstrumentationTest.php +++ b/src/Instrumentation/Symfony/tests/Integration/MessengerInstrumentationTest.php @@ -12,7 +12,7 @@ use Symfony\Component\Messenger\MessageBusInterface; use Symfony\Component\Messenger\Transport\InMemory\InMemoryTransport; use Symfony\Component\Messenger\Transport\InMemoryTransport as LegacyInMemoryTransport; -use Symfony\Component\Messenger\Transport\TransportInterface; +use Symfony\Component\Messenger\Transport\Receiver\ReceiverInterface; final class SendEmailMessage { @@ -38,52 +38,37 @@ protected function getMessenger(): MessageBusInterface protected function getTransport() { - // Symfony 6+ + // Symfony 6+ version of the transport if (class_exists(InMemoryTransport::class)) { return new InMemoryTransport(); } - // Symfony 5+ + // Symfony 5+ fallback return new LegacyInMemoryTransport(); } - /** - * @dataProvider dispatchDataProvider - * @param mixed $message - * @param string $spanName - * @param int $kind - * @param array $attributes - */ - public function test_dispatch_message($message, string $spanName, int $kind, array $attributes) + protected function getReceiver() { - $bus = $this->getMessenger(); - $bus->dispatch($message); - - $this->assertCount(1, $this->storage); - - /** @var ImmutableSpan $span */ - $span = $this->storage[0]; - - $this->assertEquals($spanName, $span->getName()); - $this->assertEquals($kind, $span->getKind()); - - foreach ($attributes as $key => $value) { - $this->assertTrue($span->getAttributes()->has($key), sprintf('Attribute %s not found', $key)); - $this->assertEquals($value, $span->getAttributes()->get($key)); + // Symfony 6+ version of the receiver + if (class_exists(ReceiverInterface::class)) { + return new InMemoryTransport(); // Example transport acting as a receiver } + + // Symfony 5+ fallback + return new LegacyInMemoryTransport(); } /** - * @dataProvider sendDataProvider + * @dataProvider dispatchDataProvider * @param mixed $message * @param string $spanName * @param int $kind * @param array $attributes */ - public function test_send_message($message, string $spanName, int $kind, array $attributes) + public function test_dispatch_message($message, string $spanName, int $kind, array $attributes) { - $transport = $this->getTransport(); - $transport->send(new Envelope($message)); + $bus = $this->getMessenger(); + $bus->dispatch($message); // Target the correct interface (MessageBusInterface) $this->assertCount(1, $this->storage); @@ -104,12 +89,12 @@ public function test_send_message($message, string $spanName, int $kind, array $ */ public function test_consume_message() { - $transport = $this->getTransport(); + $transport = $this->getReceiver(); // Use the correct receiver interface $message = new SendEmailMessage('Hello Consumer'); $envelope = new Envelope($message); - - // Simulate receiving the message via the transport - $transport->send($envelope); + + // Simulate receiving the message via ReceiverInterface::get + $transport->get(); // Simulate message consumption (processing) $bus = $this->getMessenger(); @@ -228,7 +213,7 @@ public function dispatchDataProvider(): array [ new SendEmailMessage('Hello Again'), 'DISPATCH OpenTelemetry\Tests\Instrumentation\Symfony\tests\Integration\SendEmailMessage', - SpanKind::KIND_PRODUCER, + SpanKind::KIND_PROCESS, // Correct SpanKind for dispatching [ MessengerInstrumentation::ATTRIBUTE_MESSENGER_BUS => 'Symfony\Component\Messenger\MessageBus', MessengerInstrumentation::ATTRIBUTE_MESSENGER_MESSAGE => 'OpenTelemetry\Tests\Instrumentation\Symfony\tests\Integration\SendEmailMessage', From d9338d4821aa744b0b41eec7304c60fe837a9c4f Mon Sep 17 00:00:00 2001 From: Richard Chukwu Date: Thu, 17 Oct 2024 22:35:35 +0100 Subject: [PATCH 9/9] comment removed --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 214c3baf..d4dbe320 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ "require-dev": { "composer/xdebug-handler": "^2.0", "open-telemetry/dev-tools": "dev-main", - "phpunit/phpunit": "^8.0 || ^9.5 || ^10.0" // Support for PHP 8.0/8.1 while allowing newer versions + "phpunit/phpunit": "^8.0 || ^9.5 || ^10.0" }, "autoload": { "psr-4": {