【发布时间】:2018-09-05 16:15:33
【问题描述】:
我在我的 Laravel 项目中设置了 Sentry.io。我也在使用队列。
我想知道是否可以将失败的队列发送到 Sentry?因为它们在失败时不会自动发送。
【问题讨论】:
标签: php laravel laravel-5 sentry laravel-queue
我在我的 Laravel 项目中设置了 Sentry.io。我也在使用队列。
我想知道是否可以将失败的队列发送到 Sentry?因为它们在失败时不会自动发送。
【问题讨论】:
标签: php laravel laravel-5 sentry laravel-queue
我猜你所说的失败队列是指失败的作业,因为你只需要在作业中实现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查看如何处理失败的作业。
【讨论】:
如果您将以下 sn-p 添加到错误处理程序 (as described here),只要通过 ->shouldReport() 检查,所有未捕获的异常(也包括在队列作业中抛出时)都会被捕获。
if (app()->bound('sentry') && $this->shouldReport($exception)) {
app('sentry')->captureException($exception);
}
【讨论】: