Loading Laravel Sentry package only for production
In the case that you don't want development errors making their way to Sentry for error tracking, you can use the code below to ensure that Sentry will only record exceptions when in production.
First, instead of loading the
SentryLaravelServiceProvider in the
providers array, we will load it in our
App/Providers/AppServiceProvider.php. This allows us to check the environment before loading the appropriate service providers.
Seconly, in our
App/Exceptions/Handler.php we again check for the
production environment before trying to capture the exception using Sentry. This second step prevents Sentry from trying to catch an exception when it isn't bound in the container.