9

Is there any way to disable sentry for laravel 5 on local environnement? I have removed the SENTRY_DSN entry from my .env file and it seems to work but I am not sure it's the right way. Should I add some check about env in report function? Or is there any better way? App\Exceptions\Handler looks like this:

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

3 Answers 3

8

You can check if you are in production for both the report() and render() functions.

Here is an updated App\Exceptions\Handler file for example.

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);
}

This way you still have whoops errors showing in local and a custom 500 error page for production.

Sign up to request clarification or add additional context in comments.

Comments

7

The suggested way to disable Sentry SDKs is by setting the SENTRY_DSN value to something falsey, so your intuition here is correct.

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

4 Comments

Updated answer with link to our suggested API spec
Adding this started throwing 500.
link is now 404
2

As per the official documentation here You have to set SENTRY_LARAVEL_DSN=null in your .env file

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.