abenevaut/laravel-sentry-handler is a Laravel package for laravel sentry exceptions handler.
It currently has 1 GitHub stars and 359 downloads on Packagist (latest version 1.0.2).
Install it with composer require abenevaut/laravel-sentry-handler.
Discover more Laravel packages by abenevaut
or browse all Laravel packages to compare alternatives.
Last updated
Package that facilitates sentry integration with context scoped exceptions that are able to transport data when an exception happened.
composer require abenevaut/laravel-sentry-handler
php artisan sentry:publish --dsn=
Scoped Exception vendorized in this package are able to report themself to Sentry.
Because we probably want to report all exceptions to Sentry, we are able to implement $this->reportSentry($e); to record them to Sentry.
In app/Exceptions/Handler.php, replace use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; by use abenevaut\SentryHandler\Handler as ExceptionHandler;
If you already customized your exception handler, be sure to adjust your report() method:
public function report(\Throwable $e): void
{
// Report standard exceptions to sentry
$this->reportSentry($e);
parent::report($e);
}
Note: that method is used in demo
In app/Exceptions/Handler.php, add use SentryHandlerTrait; in App\Exceptions\Handler class.
Then adjust your report() method:
public function report(\Throwable $e): void
{
// Report standard exceptions to sentry
$this->reportSentry($e);
parent::report($e);
}
php artisan sentry:test
Laravel ExceptionHandler allows an exception to report herself by implementing report() method.
We use that place to compute exception context and then throw it to Sentry.
final class MyException extends \abenevaut\SentryHandler\Contracts\ExceptionAbstract
{
/**
* @var array|string[]
*/
private array $scopes = [
/*
* Context always reported
*/
DefaultScope::class,
];
}
$exception = new MyException();
// Depending context, add relative scope
$exception->addScope( DefaultScope::class );
// You can also pass an instantiated object, if you required to compute something
$exception->addScope( new DefaultScope( ... ) );
report($exception);
// incoming soon
// incoming soon
final class DefaultScope extends \abenevaut\SentryHandler\Contracts\ScopeAbstract
{
public function handle(Scope $scope, Closure $next)
{
/*
* Stack context in Sentry scope.
* @seealso https://docs.sentry.io/platforms/php/guides/laravel/enriching-events/?original_referrer=https%3A%2F%2Fwww.google.com%2F
*/
$scope
->setUser([
// ...
])
->setTags([
// ...
]);
return $next($scope);
}
}
vendor/bin/smelly-code-detector inspect src
vendor/bin/phpunit