PHP code example of abenevaut / laravel-sentry-handler

1. Go to this page and download the library: Download abenevaut/laravel-sentry-handler library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

abenevaut / laravel-sentry-handler example snippets


public function report(\Throwable $e): void
{
    // Report standard exceptions to sentry
    $this->reportSentry($e);

    parent::report($e);
}

public function report(\Throwable $e): void
{
    // Report standard exceptions to sentry
    $this->reportSentry($e);

    parent::report($e);
}

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 

// 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);
    }
}

php artisan sentry:test