Skip to content
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

Add a way to ignore exception thrown by Symfony Messenger if there is a retry. #363

Closed
VincentLanglet opened this issue Sep 1, 2020 · 9 comments

Comments

@VincentLanglet
Copy link

Let's say I use Symfony Messenger with the following config:

framework:
    messenger:
        # Uncomment this (and the failed transport below) to send failed messages to this transport for later handling.
        # failure_transport: failed

        transports:
            # https://symfony.com/doc/current/messenger.html#transport-configuration
            async:
                dsn: '%env(MESSENGER_TRANSPORT_DSN)%'
                retry_strategy:
                    max_retries: 3
                    delay: 5000
            failed: 'doctrine://default?queue_name=failed'

The following scenarios can occur:

  1. First try: success
  2. First try: failure ; Second try: success
  3. First try: failure ; Second try: failure ; Third try: success
  4. First try: failure ; Second try: failure ; Third try: failure

Currently, case 2, 3 and 4 are sending error messages on Sentry.
Is there a way to only get error message on Sentry for case 4 ?

@Jean85
Copy link
Collaborator

Jean85 commented Sep 1, 2020

This was already implemented in the original PR, with the capture_soft_fails: false configuration option of this bundle, see https://github.com/getsentry/sentry-symfony#configuration-of-the-sdk

@Jean85 Jean85 closed this as completed Sep 1, 2020
@Jean85 Jean85 added the support label Sep 1, 2020
@VincentLanglet
Copy link
Author

VincentLanglet commented Sep 1, 2020

This was already implemented in the original PR, with the capture_soft_fails: false configuration option of this bundle, see https://github.com/getsentry/sentry-symfony#configuration-of-the-sdk

Hi @Jean85 ! Thanks for your quick answer.

I just made a try with:

messenger:
   enabled: true
   capture_soft_fails: false

And the retry strategy:

retry_strategy:
  max_retries: 3
  delay: 5000

I'm also use the monolog handler for sentry

    monolog:
        error_handler:
            enabled: true
            level: error

With a MessageHandler like

public function __invoke(Message $message)
    {
        $id = $message->getId();

        throw new \Exception("EEREYUE $id");
    }

I get the following exceptions on Sentry
image

If I use

messenger:
   enabled: true
   capture_soft_fails: true

I get each exceptions 4 times.

Shouldn't the Symfony\Component\Messenger\Exception\HandlerFailedException by send to Sentry only once if I use capture_soft_fails: false ?
Or should I add this exception to the excluded_exceptions ?

@Jean85
Copy link
Collaborator

Jean85 commented Sep 1, 2020

The issue is in the fact that you're using both the integration and the Monolog handler. The option regards the native integration only, see https://github.com/getsentry/sentry-symfony/blob/master/src/EventListener/MessengerListener.php#L36

@VincentLanglet
Copy link
Author

VincentLanglet commented Sep 1, 2020

The issue is in the fact that you're using both the integration and the Monolog handler.

Yes, but it could be great to support this :)

The option regards the native integration only, see https://github.com/getsentry/sentry-symfony/blob/master/src/EventListener/MessengerListener.php#L36

What are my options ?

  • Should I exclude the Symfony\Component\Messenger\Exception\HandlerFailedException since it's handled by your messenger support ? (Then I/we could add a word about this on the doc)
  • Does a PR is required on this repo ?

Edit: I excluded the Symfony\Component\Messenger\Exception\HandlerFailedException and it seems to work as expected.

@Jean85
Copy link
Collaborator

Jean85 commented Sep 2, 2020

Using both is not something I expect from this bundle, it leads to a lot of mess. We're considering switching to Monolog only in #337

@VincentLanglet
Copy link
Author

Using both is not something I expect from this bundle, it leads to a lot of mess.

Using only monolog wouldn't allow to ignore soft fail exceptions. Which is a pretty useful feature.

@Jean85
Copy link
Collaborator

Jean85 commented Sep 2, 2020

Ouch, you're right!

But how do you handle having both enabled? Don't you receive duplicated events anyway?

@VincentLanglet
Copy link
Author

But how do you handle having both enabled? Don't you receive duplicated events anyway?

I made multiple try with the following example

public function __invoke(Message $message)
{
     $id = $message->getId();

     throw new \Exception("EEREYUE $id");
}

With

messenger:
   enabled: true
   capture_soft_fails: true

I received 4 Exceptions and 4 HandlerFailedExceptions, so they indeed does the same things.

With

messenger:
   enabled: true
   capture_soft_fails: false

I received only 1 Exception but still 4 HandlerFailedExceptions. So I understood that the messenger integration send the Exception to Sentry, and the logger was sending the HandlerFailedExceptions.

With

    messenger:
        enabled: true
        capture_soft_fails: false
    options:
        excluded_exceptions:
            - Symfony\Component\Messenger\Exception\HandlerFailedException # Handled by messenger integration

I have no duplicate now.

If you want to switch to Monolog only, it would just need a special treatment for HandlerFailedException. But I'm not sure how/if you can know that there will be a retry...

@B-Galati
Copy link

B-Galati commented Sep 4, 2020

See my message here: #337 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants