Skip to content

Commit 793f49c

Browse files
authored
Expect exceptions in MessengerInstrumentation (#238)
* Expect exceptions in MessengerInstrumentation * Rectify wrong import
1 parent fe0214d commit 793f49c

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/MessengerInstrumentation.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public static function register(): void
8181
post: static function (
8282
MessageBusInterface $bus,
8383
array $params,
84-
Envelope $result,
84+
?Envelope $result,
8585
?\Throwable $exception
8686
): void {
8787
$scope = Context::storage()->scope();

tests/Integration/MessengerInstrumentationTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,25 @@ public function test_send_message($message, string $spanName, int $kind, array $
9898
}
9999
}
100100

101+
public function test_can_sustain_throw()
102+
{
103+
$bus = new class() implements MessageBusInterface {
104+
public function dispatch(object $message, array $stamps = []): Envelope
105+
{
106+
throw new \Exception('booo!');
107+
}
108+
};
109+
110+
try {
111+
$bus->dispatch(new SendEmailMessage('Hello Again'));
112+
} catch (\Throwable $e) {
113+
$this->assertCount(1, $this->storage);
114+
115+
/** @var ImmutableSpan $span */
116+
$span = $this->storage[0];
117+
}
118+
}
119+
101120
public function sendDataProvider(): array
102121
{
103122
return [

0 commit comments

Comments
 (0)