-
Notifications
You must be signed in to change notification settings - Fork 96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
KIND::CONSUMER instrumentation implemented #307
Changes from all commits
018e7fd
66fa258
bdbb36f
730c424
8ad2de6
ea5f1b1
f6a23dd
3e46678
da0cf7b
8204d40
d9338d4
97ffab1
84e16ed
9e81e32
ee4522d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
{ | ||
|
@@ -35,14 +35,26 @@ protected function getMessenger(): MessageBusInterface | |
{ | ||
return new MessageBus(); | ||
} | ||
|
||
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(); | ||
} | ||
|
||
protected function getReceiver() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this different enough from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @RichardChukwu have you had any time to look further into this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hey @ChrisLightfootWild, thanks for asking. Not really, I'll appreciate any assistance please |
||
{ | ||
// 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(); | ||
} | ||
|
||
|
@@ -56,8 +68,7 @@ protected function getTransport() | |
public function test_dispatch_message($message, string $spanName, int $kind, array $attributes) | ||
{ | ||
$bus = $this->getMessenger(); | ||
|
||
$bus->dispatch($message); | ||
$bus->dispatch($message); // Target the correct interface (MessageBusInterface) | ||
|
||
$this->assertCount(1, $this->storage); | ||
|
||
|
@@ -73,6 +84,36 @@ public function test_dispatch_message($message, string $spanName, int $kind, arr | |
} | ||
} | ||
|
||
/** | ||
* Test consumer span when processing a message | ||
*/ | ||
public function test_consume_message() | ||
{ | ||
$transport = $this->getReceiver(); // Use the correct receiver interface | ||
$message = new SendEmailMessage('Hello Consumer'); | ||
$envelope = new Envelope($message); | ||
|
||
// Simulate receiving the message via ReceiverInterface::get | ||
$transport->get(); | ||
|
||
// 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 | ||
|
@@ -172,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', | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not "dispatch"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The span types and names should be consistent with the spec here:
https://opentelemetry.io/docs/specs/semconv/messaging/messaging-spans/#span-kind
But it's kind of confusing TBH, it mentions both "publish" and "send", in the example it gives
publish shop.orders
, but then it doesn't givepublish
in operation type or span kind. 🤯@brettmc can you clarify the spec wording here maybe?