kiwilan/sentinel-laravel

PHP package for Laravel to send errors to Sentinel.

0.0.33 2023-10-11 15:03 UTC

README

PHP Version Laravel Version

Latest Version on Packagist GitHub Tests Action Status Total Downloads License codecov

PHP package for Laravel to send errors to Sentinel.

Note

Sentinel is an open-source error tracking tool.

Installation

You can install the package via composer:

composer require kiwilan/sentinel-laravel

You can publish the config file with:

php artisan vendor:publish --tag="sentinel-config"

This is the contents of the published config file:

return [
    /**
     * If you want to disable Sentinel, set `SENTINEL_ENABLED` to `false`.
     */
    'enabled' => env('SENTINEL_ENABLED', true),
    /**
     * Sentinel host where your application is registered.
     */
    'host' => env('SENTINEL_HOST', 'http://app.sentinel.test'),
    /**
     * Token is used to authenticate your application with Sentinel.
     */
    'token' => env('SENTINEL_TOKEN'),
    /**
     * If you want to throw Sentinel errors for debug, set `SENTINEL_DEBUG` to `true`.
     * WARNING: do not use it on production.
     */
    'debug' => env('SENTINEL_DEBUG', false),
];

Usage

Automatic

Just execute the sentinel:install Artisan command. It will automatically install the package and configure it for you.

php artisan sentinel:install

Manual

In app/Exceptions/Handler.php

<?php

namespace App\Exceptions;

use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Throwable;

class Handler extends ExceptionHandler
{
  /**
   * Register the exception handling callbacks for the application.
   */
  public function register(): void
  {
    $this->reportable(function (Throwable $e) {
      \Kiwilan\Sentinel\Facades\Sentinel::register($e);
    });
  }
}

If you want to debug your installation, you can set true to throwErrors: \Kiwilan\Sentinel\Facades\Sentinel::register($e, throwErrors: true).

Warning

Do not use throwErrors in production, if Sentinel instance is not available, your application will crash.

Verify your installation

Use the sentinel:test Artisan command to verify your installation.

php artisan sentinel:test

You can verify your installation by throwing an exception from a route or controller.

For example, in routes/web.php:

Route::get('/debug-sentinel', function () {
  throw new \Exception('Sentinel error!');
});

Testing

cp .env.example .env
composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Credits

License

The MIT License (MIT). Please see License File for more information.