ryderasking / laravel-ai-trace
LangSmith-style waterfall tracing for Laravel AI SDK workloads.
Requires
- php: ^8.3
- illuminate/auth: ^12.0 || ^13.0
- illuminate/console: ^12.0 || ^13.0
- illuminate/database: ^12.0 || ^13.0
- illuminate/http: ^12.0 || ^13.0
- illuminate/routing: ^12.0 || ^13.0
- illuminate/support: ^12.0 || ^13.0
- illuminate/view: ^12.0 || ^13.0
- livewire/livewire: ^3.6 || ^4.0
Requires (Dev)
- laravel/pint: ^1.18
- orchestra/testbench: ^10.0
- phpunit/phpunit: ^11.0
README
Laravel AI Trace is a tracing and debugging package for AI workflows built with Laravel AI SDK (laravel/ai).
It captures full trace -> span -> event lifecycle data with SDK-native hooks so you can inspect execution order, retries, tool calls, streaming milestones, failures, and timing with waterfall-style visibility.
The dashboard provides period-based trend cards, a filterable trace explorer, and quick drill-in links for incident investigation and performance triage.
Compatibility
- Laravel:
12+(currently tested on12.xand13.x) - PHP:
8.3+ - Livewire:
3.6+(including4.x) - Laravel AI SDK (
laravel/ai): currently validated againstv0.3.2
How It Works
Laravel AI Trace subscribes to Laravel AI SDK lifecycle events (for example agent start/end, tool start/end, stream completion, and failover events), then:
- Correlates each callback to a trace and active span context.
- Persists traces, spans, and events in relational tables.
- Deduplicates repeated callbacks inside a configurable TTL window.
- Applies privacy mode/redaction before storing sensitive content.
- Serves dashboard/query data through package services.
This package is SDK-native by design. It does not use HTTP fallback instrumentation.
Dashboard Stack
The dashboard is package-owned UI and uses:
- Livewire components for card rendering, polling, filters, and URL-backed state
- Blade components for layout, cards, tables, and inspector primitives
- Alpine.js + Chart.js for chart interactions and dataset updates
- Tailwind CSS for styling (with compiled package assets)
The design is inspired by Laravel Pulse, but the dashboard does not require a runtime dependency on laravel/pulse.
Installation
- Install Laravel AI SDK (if not already installed):
composer require laravel/ai
- Install Laravel AI Trace:
composer require ryderasking/laravel-ai-trace
- Publish package configuration and migrations:
php artisan vendor:publish --tag=ai-trace-config php artisan vendor:publish --tag=ai-trace-migrations
- Run migrations:
php artisan migrate
- Optional smoke test:
php artisan ai-trace:smoke
Dashboard Authorization Setup
Dashboard authorization is controlled by the host application via gate.
By default, Laravel AI Trace checks gate viewAiTrace (ai-trace.dashboard.authorization_gate). Define it in your AppServiceProvider:
<?php namespace App\Providers; use App\Models\User; use Illuminate\Support\Facades\Gate; use Illuminate\Support\ServiceProvider; class AppServiceProvider extends ServiceProvider { public function boot(): void { Gate::define('viewAiTrace', function (User $user): bool { return $user->is_admin; }); } }
Behavior details:
- If the configured gate exists, access is decided by that gate.
- If no gate is defined, dashboard access falls back to
localenvironment only. - If
ai-trace.dashboard.enabledisfalse, the dashboard routes return404.
Configuration
Published config file: config/ai-trace.php
Important keys:
ai-trace.enabled: master package toggleai-trace.track_ai_sdk: subscribe/unsubscribe SDK event tracingai-trace.record_content_mode:none,hash,redacted,fullai-trace.sample_rate: trace sampling (0..1)ai-trace.dedup_ttl_seconds: event deduplication windowai-trace.stream.max_events_per_invocation: cap stored stream timeline eventsai-trace.retention_days: retention horizon for stored tracesai-trace.dashboard.*: domain/path/middleware/gate settings
Routes
Dashboard routes are registered by the package service provider:
ai-trace.dashboard:/{dashboard-path}(default path:/ai-trace)ai-trace.dashboard.trace:/{dashboard-path}/traces/{traceId}
Data Model
Core persistence tables:
ai_traces: one row per end-to-end workflowai_spans: one row per operation (agent/tool/operation step)ai_span_events: timeline markers for span-level events
This structure enables parent-child waterfall reconstruction and detailed drilldown inspection.
Production Notes
- Keep
record_content_mode=redacted(or stricter) for sensitive environments. - Use gate-based authorization for all non-local dashboard access.
- Tune
sample_rateand stream event caps based on traffic profile. - Plan retention cleanup strategy based on
retention_daysand compliance needs.

