PHP code example of tracefast / laravel-ai-observability

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

    

tracefast / laravel-ai-observability example snippets


use Tracefast\LaravelAiObservability\Facades\AiObservability;

$response = AiObservability::withSession(
    sessionId: $conversation->uuid,
    callback: fn () => $agent->prompt($message),
    userId: $user->id,
    attributes: [
        'tenant.id' => (string) $tenant->id,
        'workflow.name' => 'support-triage',
    ],
);

$response = AiObservability::withAttributes([
    'tenant.id' => (string) $tenant->id,
    'workflow.name' => 'support-triage',
], fn () => $agent->prompt($message));

use Tracefast\LaravelAiObservability\Contracts\Exporter;
use Tracefast\LaravelAiObservability\Data\Trace;

final class WebhookExporter implements Exporter
{
    public function export(Trace $trace): void
    {
        // Send $trace->toArray() to your destination.
    }
}

use App\Observability\WebhookExporter;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Support\ServiceProvider;
use Tracefast\LaravelAiObservability\AiObservability;
use Tracefast\LaravelAiObservability\Contracts\Exporter;

final class AppServiceProvider extends ServiceProvider
{
    public function boot(AiObservability $observability): void
    {
        $observability->extend(
            'webhook',
            fn (Application $app, array $config, string $name): Exporter => new WebhookExporter(),
        );
    }
}

'exporters' => [
    'webhook' => [
        'driver' => 'webhook',
    ],
],
bash
php artisan vendor:publish --tag=ai-observability-config
bash
php artisan vendor:publish --tag=ai-observability-migrations
php artisan migrate