Skip to content

Commit e2422ff

Browse files
authored
Individual captures of DelayedMessageHandlingException (#760)
1 parent ed9f9bb commit e2422ff

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

CHANGELOG.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## 4.12.0
4+
5+
### Features
6+
7+
- Report individual exceptions from `DelayedMessageHandlingException` [(#760)](https://github.com/getsentry/sentry-symfony/pull/760)
8+
39
## 4.11.0
410

511
The Sentry SDK team is happy to announce the immediate availability of Sentry Symfony SDK v4.11.0.
@@ -167,7 +173,7 @@ This release contains a colorful bouquet of new features.
167173
```
168174

169175
- Use the `_route` attribute as the transaction name [(#692)](https://github.com/getsentry/sentry-symfony/pull/692)
170-
176+
171177
If you're using named routes, the SDK will default to use this attribute as the transaction name.
172178
With this change, you should be able to see a full list of your transactions on the performance page,
173179
instead of `<< unparameterized >>`.

src/EventListener/MessengerListener.php

+8-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Sentry\State\Scope;
1212
use Symfony\Component\Messenger\Event\WorkerMessageFailedEvent;
1313
use Symfony\Component\Messenger\Event\WorkerMessageHandledEvent;
14+
use Symfony\Component\Messenger\Exception\DelayedMessageHandlingException;
1415
use Symfony\Component\Messenger\Exception\HandlerFailedException;
1516
use Symfony\Component\Messenger\Stamp\BusNameStamp;
1617

@@ -94,7 +95,13 @@ public function handleWorkerMessageHandledEvent(WorkerMessageHandledEvent $event
9495
private function captureException(\Throwable $exception, bool $willRetry): void
9596
{
9697
if ($exception instanceof HandlerFailedException) {
97-
foreach ($exception->getNestedExceptions() as $nestedException) {
98+
$exception = $exception->getNestedExceptions();
99+
} elseif ($exception instanceof DelayedMessageHandlingException) {
100+
$exception = $exception->getExceptions();
101+
}
102+
103+
if (\is_array($exception)) {
104+
foreach ($exception as $nestedException) {
98105
$this->captureException($nestedException, $willRetry);
99106
}
100107

tests/EventListener/MessengerListenerTest.php

+11
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Component\Messenger\Envelope;
1616
use Symfony\Component\Messenger\Event\WorkerMessageFailedEvent;
1717
use Symfony\Component\Messenger\Event\WorkerMessageHandledEvent;
18+
use Symfony\Component\Messenger\Exception\DelayedMessageHandlingException;
1819
use Symfony\Component\Messenger\Exception\HandlerFailedException;
1920
use Symfony\Component\Messenger\MessageBusInterface;
2021
use Symfony\Component\Messenger\Stamp\BusNameStamp;
@@ -113,6 +114,16 @@ public function handleWorkerMessageFailedEventDataProvider(): \Generator
113114
false,
114115
];
115116

117+
yield 'envelope.throwable INSTANCEOF DelayedMessageHandlingException' => [
118+
$exceptions,
119+
$this->getMessageFailedEvent($envelope, 'receiver', new DelayedMessageHandlingException($exceptions), false),
120+
[
121+
'messenger.receiver_name' => 'receiver',
122+
'messenger.message_class' => \get_class($envelope->getMessage()),
123+
],
124+
false,
125+
];
126+
116127
yield 'envelope.throwable INSTANCEOF HandlerFailedException - RETRYING' => [
117128
$exceptions,
118129
$this->getMessageFailedEvent($envelope, 'receiver', new HandlerFailedException($envelope, $exceptions), true),

0 commit comments

Comments
 (0)