在本地环境下禁用 Laravel 的 Sentry。

9
有没有办法在本地环境下禁用laravel 5的sentry?我已从我的.env文件中移除了SENTRY_DSN条目,看起来它已经生效了,但我不确定这是正确的方法。我应该在report函数中添加一些关于env的检查吗?还是有更好的方法?App\Exceptions\Handler 如下所示:
public function report(Exception $e)
{
    if ($this->shouldReport($e)) {
        app('sentry')->captureException($e);
    }
    parent::report($e);
}
3个回答

7
你可以检查 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);
}

这样,在本地仍会显示抱歉错误,而在生产环境中有自定义的500错误页面。

6

更新答案并附上我们建议的API规范链接。 - David Cramer
添加这个开始抛出500错误。 - Abhishek Saini
2
链接现在是404。 - Salim Djerbouh
2
请更新链接至 https://docs.sentry.io/platforms/php/guides/laravel/。 - Avdhesh Solanki

2
根据官方文档 此处 您需要在 .env 文件中设置 SENTRY_LARAVEL_DSN=null。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接