Sentry Please check if your DSN is set properly in your config or .env as `SENTRY_LARAVEL_DSN`

Viewed 723

I've installed Sentry on my Laravel project but I can't run it, whenever I run command php artisan sentry:test the result is:

[Sentry] DSN discovered!
[Sentry] Generating test Event
[Sentry] Sending test Event
[Sentry] There was an error sending the test event.
[Sentry] Please check if your DSN is set properly in your config or `.env` as `SENTRY_LARAVEL_DSN`.


but I've added the DSN in my .env file

2 Answers

Make sure to put the DSN in the .env file like this

SENTRY_LARAVEL_DSN=https://34412344274048ccbfasfdgdffaf7f38d47c@o111111111.ingest.sentry.io/222334456

and don't forget to cache the config

PHP artisan config:cache

You find you DNS address in your Sentry account under "Client Keys" in your project settings.

When you have located the DNS address copy it and add it to your .env file like this:

SENTRY_LARAVEL_DSN=YOUR_SENTRY_DSN_HERE

To handle unhandled errors you also need to put this in your App/Exceptions/Handler.php:

public function register()
{
    $this->reportable(function (Throwable $e) {
        if (app()->bound('sentry')) {
            app('sentry')->captureException($e);
        }
    });
}

You probably already have a register method there. If it empty you should replace it with this. If you have something there you probably have to merge this register with your current one. If you want help with that, post your current register method here.

After this php artisan sentry:test should work. You might have to clear the cache if you have config cache turned on in your environment. After you have verified that is works you should probably remove the DSN from you .env in your local environment and add it to your production and staging environments if you have any.

Here is a link to the Sentry documentation: https://docs.sentry.io/platforms/php/guides/laravel/

I would also recommend that you enable performance monitoring. It is a great feature!

Related