Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/abenevaut/laravel-sentry-handler
Package that facilitates sentry integration with context scoped exceptions that are able to transport data when an exception happened. [READONLY]
https://github.com/abenevaut/laravel-sentry-handler
crash-reporting laravel sentry
Last synced: 7 days ago
JSON representation
Package that facilitates sentry integration with context scoped exceptions that are able to transport data when an exception happened. [READONLY]
- Host: GitHub
- URL: https://github.com/abenevaut/laravel-sentry-handler
- Owner: abenevaut
- License: gpl-3.0
- Created: 2022-09-15T19:12:31.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2024-04-14T12:02:49.000Z (9 months ago)
- Last Synced: 2024-12-23T03:51:45.251Z (13 days ago)
- Topics: crash-reporting, laravel, sentry
- Language: PHP
- Homepage: https://github.com/abenevaut/opensource/releases?q=laravel-sentry-handler-&expanded=true
- Size: 7.1 MB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE
- Code of conduct: .github/CODE_OF_CONDUCT.md
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# laravel-sentry-handler
Package that facilitates sentry integration with context scoped exceptions that are able to transport data when an exception happened.
## Install
```shell
composer require abenevaut/laravel-sentry-handler
php artisan sentry:publish --dsn=
```## Usage
### Update ExceptionHandler
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.#### Inherited Handler
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:
```php
public function report(\Throwable $e): void
{
// Report standard exceptions to sentry
$this->reportSentry($e);parent::report($e);
}
```Note: that method is used in [demo](https://github.com/abenevaut/demo-laravel-sentry-handler)
#### Handler Trait
In `app/Exceptions/Handler.php`, add `use SentryHandlerTrait;` in `App\Exceptions\Handler` class.
Then adjust your `report()` method:
```php
public function report(\Throwable $e): void
{
// Report standard exceptions to sentry
$this->reportSentry($e);parent::report($e);
}
```#### Test Sentry with standard exceptions
```
php artisan sentry:test
```### Scoped Exceptions
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.```php
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);
```- Set exception severity
```php
// incoming soon
```- Send Sentry message
```php
// incoming soon
```### What a scope
```php
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);
}
}
```## Tests
```shell
vendor/bin/smelly-code-detector inspect src
vendor/bin/phpunit
```