dragon-code / sentriable-laravel
sentry/sentry-laravel package extension
Fund package maintenance!
TheDragonCode
Open Collective
Boosty
Yoomoney
Requires
- php: ^7.2.5|^8.0
- illuminate/console: ^6.0|^7.0|^8.0|^9.0
- illuminate/contracts: ^6.0|^7.0|^8.0|^9.0
- illuminate/http: ^6.0|^7.0|^8.0|^9.0
- illuminate/support: ^6.0|^7.0|^8.0|^9.0
- illuminate/validation: ^6.0|^7.0|^8.0|^9.0
- sentry/sentry-laravel: ^2.10
Requires (Dev)
- orchestra/testbench: ^4.0|^5.0|^6.0|^7.0
Suggests
- symfony/thanks: Give thanks (in the form of a GitHub) to your fellow PHP package maintainers
Conflicts
README
Installation
To get the latest version, simply require the project using Composer:
$ composer require dragon-code/sentriable-laravel
Or manually update require
block of composer.json
and run composer update
.
{ "require": { "dragon-code/sentriable-laravel": "^2.0" } }
Upgrade from andrey-helldar/sentriable-laravel
- Replace
"andrey-helldar/sentriable-laravel": "^1.0"
with"dragon-code/sentriable-laravel": "^2.0"
in thecomposer.json
file; - Replace
Helldar\Sentry
namespace prefix withDragonCode\Sentry
; - Call the
composer update
console command.
Lumen
This package is focused on Laravel development, but it can also be used in Lumen with some workarounds. Because Lumen works a little different, as it is like a barebone version of
Laravel and the main configuration parameters are instead located in bootstrap/app.php
, some alterations must be made.
You can install Laravel Lang Publisher in app/Providers/AppServiceProvider.php
, and uncommenting this line that registers the App Service Providers so it can properly load.
// $app->register(App\Providers\AppServiceProvider::class);
If you are not using that line, that is usually handy to manage gracefully multiple Lumen installations, you will have to add this line of code under
the Register Service Providers
section of your bootstrap/app.php
.
$app->register(\DragonCode\Sentry\ServiceProvider::class);
How to use
Add Sentry reporting to App/Exceptions/Handler.php
.
For Laravel 7.x and later
use DragonCode\Sentry\Traits\Sentriable; use Throwable; public function report(Throwable $exception) { parent::report($exception); if ($this->shouldReport($e)) { $this->sentryException($e); } }
For Laravel 6.x
use DragonCode\Sentry\Traits\Sentriable; use Exception; public function report(Exception $exception) { parent::report($exception); if ($this->shouldReport($e)) { $this->sentryException($e); } }
For more information on configuring the Sentry package, see here.
Using code elsewhere
use DragonCode\Sentry\Traits\Sentriable use Throwable; protected function handle() { try { // some code } catch (Throwable $e) { $this->sentryException($e); } }
Use in loops with flushing
use DragonCode\Sentry\Traits\Sentriable; use Throwable; protected function handle() { foreach ($this->values as $item) { try { $this->sentryFlush(); // some code } catch (Throwable $e) { $this->sentryException($e); } } }
Versioning
To get the current version of the application, run the command php artisan git:version
.
If a tag is set on the current commit, it will be passed in the release
field of the Sentry, otherwise the sha of the current commit will be taken.
It is better to do this once when deploying the application.
You also need to uncomment the release
key in the config/sentry.php
file and specify the following value:
use DragonCode\Sentry\Facades\Sha; return [ // ... 'release' => Sha::get() // ... ];
License
This package is licensed under the MIT License.