【问题标题】:Disable sentry for laravel on local environment在本地环境中禁用 laravel 的哨兵
【发布时间】:2016-10-15 06:56:44
【问题描述】:

有没有办法在本地环境中禁用 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);
}

【问题讨论】:

    标签: php laravel laravel-5 sentry


    【解决方案1】:

    您可以检查您是否正在生产 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 错误页面。

    【讨论】:

      【解决方案2】:

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

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

      【讨论】:

      【解决方案3】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2021-06-27
        • 2014-01-21
        • 2014-06-11
        • 1970-01-01
        • 1970-01-01
        • 2016-04-14
        • 1970-01-01
        相关资源
        最近更新 更多