PHP code example of alby / report

1. Go to this page and download the library: Download alby/report 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/ */

    

alby / report example snippets


use Alby\Report\Alby;

Alby::init([
    'dsn'         => getenv('ALBY_DSN'),  // https://<key>@alby.sh/ingest/v1/<app-id>
    'release'     => '1.4.2',
    'environment' => 'production',
]);

// Uncaught exceptions and fatal errors are sent automatically.

// Manual report:
try {
    doThing();
} catch (\Throwable $e) {
    Alby::captureException($e);
}

// Non-error events:
Alby::captureMessage('Failed to acquire lease', 'warning');

// Enrich the scope:
Alby::setUser(['id' => 'u_412', 'email' => '[email protected]']);
Alby::setTag('region', 'eu-west-3');
Alby::setContext('billing_tenant', ['plan' => 'pro', 'seats' => 12]);
Alby::addBreadcrumb(['type' => 'http', 'message' => 'GET /api/orders/42']);

// Before exit (e.g. in a worker):
Alby::flush(2000);

->withExceptions(function (Exceptions $exceptions) {
    $exceptions->report(fn (\Throwable $e) => \Alby\Report\Alby::captureException($e));
})

public function register(): void
{
    $this->reportable(fn (\Throwable $e) => \Alby\Report\Alby::captureException($e));
}

'breadcrumbs' => [
    'queries' => true,   // DB query breadcrumbs
    'routes'  => true,   // Route-matched breadcrumbs
],
bash
php artisan vendor:publish --tag=alby-report-config