在本地环境中禁用 laravel 的哨兵

Disable sentry for laravel on local environment

有什么方法可以在本地环境中禁用 laravel 5 的哨兵吗?我已经从我的 .env 文件中删除了 SENTRY_DSN 条目并且 它似乎有效 但我不确定这是正确的方法。我应该在 report 函数中添加一些关于 env 的检查吗?或者有什么更好的方法吗? App\Exceptions\Handler 看起来像这样:

public function report(Exception $e)
{
    if ($this->shouldReport($e)) {
        app('sentry')->captureException($e);
    }
    parent::report($e);
}

建议的禁用 Sentry SDK 的方法是将 SENTRY_DSN 值设置为错误的值,因此您的直觉是正确的。

https://docs.getsentry.com/hosted/clientdev/#usage-for-end-users

您可以检查 report() 和 render() 函数是否都在生产中。

例如,这是一个更新的 App\Exceptions\Handler 文件。

public function report(Exception $e)
{
    if (app()->environment('production') && $this->shouldReport($e)) {
        app('sentry')->captureException($e);
    }

    parent::report($e);
}

...

public function render($request, Exception $e)
{
    if ($e instanceof ModelNotFoundException) {
        $e = new NotFoundHttpException($e->getMessage(), $e);
    }

    if (app()->environment('production')) {
        return response()->view('errors.500', null, 500);
    }

    return parent::render($request, $e);
}

这样你仍然有 whoops 错误显示在本地和生产的自定义 500 错误页面。

根据官方文档here 您必须在 .env 文件中设置 SENTRY_LARAVEL_DSN=null