【问题标题】:Send error report to sentry within Laravel queue向 Laravel 队列中的哨兵发送错误报告
【发布时间】:2018-09-05 16:15:33
【问题描述】:

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

我想知道是否可以将失败的队列发送到 Sentry?因为它们在失败时不会自动发送。

【问题讨论】:

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


    【解决方案1】:

    我猜你所说的失败队列是指失败的作业,因为你只需要在作业中实现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查看如何处理失败的作业。

    【讨论】:

      【解决方案2】:

      如果您将以下 sn-p 添加到错误处理程序 (as described here),只要通过 ->shouldReport() 检查,所有未捕获的异常(也包括在队列作业中抛出时)都会被捕获。

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

      【讨论】:

        猜你喜欢
        • 2021-05-07
        • 2014-06-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-09-09
        • 1970-01-01
        • 2021-01-25
        相关资源
        最近更新 更多