Search code examples
phplaravellaravel-5sentrylaravel-queue

Send error report to sentry within Laravel queue


I have Sentry.io set-up on my Laravel project. I'm also using Queues.

I was wondering if it was possible to send failed queues to Sentry? As they don't automatically send when they fail.


Solution

  • By failed queues I guess you mean failed jobs, for that you just need to implement the failed() method inside the job:

    /**
     * Handle a job failure.
     *
     * @return void
     */
    public function failed(\Exception $exception)
    {
        // Send exception data to sentry.io
        // It should catch it by default since it throws an exception
        // But you can force a report manually
        app('sentry')->captureException($exception);
    }
    

    Check how to deal with failed jobs in Laravel documentation.