Search code examples
phplaravelsentry

Laravel queue stalls when used with sentry


i have a working project written in laravel, i've integrated Sentry to monitor for errors, i followed instructions on their site, basically just

composer require sentry/sentry-laravel

and in my App/Exceptions/Handler.php

if (app()->bound('sentry') && $this->shouldReport($exception)) {
    app('sentry')->captureException($exception);
}

Now this works fine, i see errors in sentry. But at the other end of the app wherever i use queue, for example i have "forgot password" notification and it implements ShouldQueue class, practically:

<?php

namespace App\Notifications\Auth;

use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;

class PasswordResetRequest extends Notification implements ShouldQueue
{
    use Queueable;

    protected $token;

    public function __construct($token)
    {
        $this->token = $token;
    }

    public function via($notifiable)
    {
        return ['mail'];
    }

    public function toMail($notifiable)
    {
        $url = url('/password/find/'.$this->token);
        return (new MailMessage)
            ->line('You are receiving this email because we received a password reset request for your account.')
            ->action('Reset Password', url($url))
            ->line('If you did not request a password reset, no further action is required.');
    }
}

And when triggered works as expected, i have a new record in jobs table (i have database as queue driver)

now when i start my worker

php artisan queue:work

it stalls it works last job over and over

laravel queue worker

there is no mail sent or received...

By the way this is only when i have reporting in sentry, if i remove those lines in App/Exceptions/Handler.php in report() method it's all good, also if i remove queue from notification it works, only the combinatio of sentry error reporting and notification queuing is making me a big problem.


Solution

  • Unfortunately, Sentry-laravel doesn't work with queues.

    Please, see this issue on their GitHub repo to get more info about it:

    https://github.com/getsentry/sentry-laravel/issues/18

    There is another issue (open) where they are trying to fix it:

    https://github.com/getsentry/sentry-laravel/pull/228

    If you really need to put these logs on a queue now you should use https://github.com/twineis/raven-php.