将错误报告发送到Laravel队列中的哨兵

时间:2018-03-27 09:54:32

标签: php laravel laravel-5 sentry laravel-queue

我在Laravel项目上设置了Sentry.io。我也在使用队列。

我想知道是否有可能向Sentry发送失败的队列?因为他们失败时不会自动发送。

2 个答案:

答案 0 :(得分:4)

由于队列失败,我猜你的意思是失败的工作,因为你只需要在工作中实现failed()方法:

/**
 * 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);
}

检查如何处理Laravel documentation中失败的作业。

答案 1 :(得分:2)

如果将以下代码段添加到错误处理程序(as described here)中,则只要它们未通过->shouldReport()检查,就会捕获所有未捕获的异常(也包括在队列作业中)。

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