7

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

Amir Salehi
  • 101
  • 2
  • 9
  • As the previous output suggests, the DSN was discovered and everything but there was an error sending the test event. This means the DSN is invalid/broken or it can't reach the Sentry instance the DSN points to. Are you using sentry.io or a self-hosted instance? And are you on Windows? – Alex Sep 12 '21 at 15:38

2 Answers2

2

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
Ashraf Basry
  • 58
  • 1
  • 5
0

You find your DSN in your Sentry account under "Client Keys" in your project settings.

When you have located the DSN 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 (php artisan config:clear). 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!

Alex
  • 1,425
  • 11
  • 25
Pelmered
  • 2,727
  • 21
  • 22