Skip to content

Commit

Permalink
Individual captures of DelayedMessageHandlingException (#760)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeroeny committed Sep 14, 2023
1 parent ed9f9bb commit e2422ff
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 4.12.0

### Features

- Report individual exceptions from `DelayedMessageHandlingException` [(#760)](https://github.com/getsentry/sentry-symfony/pull/760)

## 4.11.0

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

- Use the `_route` attribute as the transaction name [(#692)](https://github.com/getsentry/sentry-symfony/pull/692)

If you're using named routes, the SDK will default to use this attribute as the transaction name.
With this change, you should be able to see a full list of your transactions on the performance page,
instead of `<< unparameterized >>`.
Expand Down
9 changes: 8 additions & 1 deletion src/EventListener/MessengerListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Sentry\State\Scope;
use Symfony\Component\Messenger\Event\WorkerMessageFailedEvent;
use Symfony\Component\Messenger\Event\WorkerMessageHandledEvent;
use Symfony\Component\Messenger\Exception\DelayedMessageHandlingException;
use Symfony\Component\Messenger\Exception\HandlerFailedException;
use Symfony\Component\Messenger\Stamp\BusNameStamp;

Expand Down Expand Up @@ -94,7 +95,13 @@ public function handleWorkerMessageHandledEvent(WorkerMessageHandledEvent $event
private function captureException(\Throwable $exception, bool $willRetry): void
{
if ($exception instanceof HandlerFailedException) {
foreach ($exception->getNestedExceptions() as $nestedException) {
$exception = $exception->getNestedExceptions();
} elseif ($exception instanceof DelayedMessageHandlingException) {
$exception = $exception->getExceptions();
}

if (\is_array($exception)) {
foreach ($exception as $nestedException) {
$this->captureException($nestedException, $willRetry);
}

Expand Down
11 changes: 11 additions & 0 deletions tests/EventListener/MessengerListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Symfony\Component\Messenger\Envelope;
use Symfony\Component\Messenger\Event\WorkerMessageFailedEvent;
use Symfony\Component\Messenger\Event\WorkerMessageHandledEvent;
use Symfony\Component\Messenger\Exception\DelayedMessageHandlingException;
use Symfony\Component\Messenger\Exception\HandlerFailedException;
use Symfony\Component\Messenger\MessageBusInterface;
use Symfony\Component\Messenger\Stamp\BusNameStamp;
Expand Down Expand Up @@ -113,6 +114,16 @@ public function handleWorkerMessageFailedEventDataProvider(): \Generator
false,
];

yield 'envelope.throwable INSTANCEOF DelayedMessageHandlingException' => [
$exceptions,
$this->getMessageFailedEvent($envelope, 'receiver', new DelayedMessageHandlingException($exceptions), false),
[
'messenger.receiver_name' => 'receiver',
'messenger.message_class' => \get_class($envelope->getMessage()),
],
false,
];

yield 'envelope.throwable INSTANCEOF HandlerFailedException - RETRYING' => [
$exceptions,
$this->getMessageFailedEvent($envelope, 'receiver', new HandlerFailedException($envelope, $exceptions), true),
Expand Down

0 comments on commit e2422ff

Please sign in to comment.