andrey-helldar/sentriable-laravel

This package is abandoned and no longer maintained. The author suggests using the dragon-code/sentriable-laravel package instead.

sentry/sentry-laravel package extension

v2.0.1 2021-11-16 20:13 UTC

This package is auto-updated.

Last update: 2021-11-16 20:14:09 UTC


README

Sentriable Laravel

Stable Version Unstable Version Total Downloads License

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

  1. Replace "andrey-helldar/sentriable-laravel": "^1.0" with "dragon-code/sentriable-laravel": "^2.0" in the composer.json file;
  2. Replace Helldar\Sentry namespace prefix with DragonCode\Sentry;
  3. 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.