PHP code example of tracelytics / tracelytics-laravel

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

    

tracelytics / tracelytics-laravel example snippets




use Illuminate\Foundation\Application;
use Illuminate\Foundation\Configuration\Exceptions;
use Illuminate\Foundation\Configuration\Middleware;
use Tracelytics\Laravel\Integration;

return Application::configure(basePath: dirname(__DIR__))
    ->withRouting(
        web: __DIR__.'/../routes/web.php',
        commands: __DIR__.'/../routes/console.php',
        health: '/up',
    )
    ->withMiddleware(function (Middleware $middleware) {
        // ...
    })
    ->withExceptions(function (Exceptions $exceptions) {
        Integration::handles($exceptions);
    })->create();

namespace App\Exceptions;

use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Tracelytics\Laravel\TracelyticsClient;
use Throwable;

class Handler extends ExceptionHandler
{
    public function register(): void
    {
        $this->reportable(function (Throwable $e) {
            if (app()->bound(TracelyticsClient::class)) {
                app(TracelyticsClient::class)->captureException($e);
            }
        });
    }
}

use Tracelytics\Laravel\Facades\Tracelytics;

try {
    // Dangerous operation
} catch (\Throwable $e) {
    Tracelytics::captureException($e, [
        'extra_info' => 'Payment processing context',
    ]);
}
bash
php artisan vendor:publish --tag=tracelytics-config
bash
php artisan tracelytics:test