iazaran/trace-replay
TraceReplay is an execution tracer for Laravel: instrument steps, view a waterfall timeline, auto-trace jobs/commands, track DB/cache/mail, and deterministically replay HTTP with JSON diffs. Includes PII masking, sampling, multi-tenant scoping, and AI debug prompts.
Installation:
composer require iazaran/trace-replay
Publish config and migrations:
php artisan vendor:publish --provider="Iazaran\TraceReplay\TraceReplayServiceProvider"
php artisan migrate
First Use Case:
use Iazaran\TraceReplay\Facades\TraceReplay;
Route::get('/example', function () {
TraceReplay::start('User Profile Load'); // Start a named trace
$user = User::with('posts')->find(1);
TraceReplay::end(); // End the trace
return view('profile', compact('user'));
});
/trace-replay) or CLI:
php artisan trace-replay:replay <trace_id>
Where to Look First:
/trace-replay for visualizing traces.TraceReplay::start()/end() and TraceReplay::instrument() for manual instrumentation.Automatic Tracing:
TraceReplay::middleware(function ($request) {
return TraceReplay::start('Request: ' . $request->path());
});
TraceReplay::auto() to enable globally (configurable in config/trace-replay.php).Manual Instrumentation:
TraceReplay::instrument('Fetch User Data', function () {
return User::find(1);
});
TraceReplay::step('Validate Order', ['order_id' => $order->id]);
Replay Integration:
$trace = TraceReplay::replay('http://example.com/api/order/123');
TraceReplay::mock('Stripe', function ($request) {
return ['status' => 'paid'];
});
AI-Assisted Debugging:
$fix = TraceReplay::ai()->generateFix($traceId, 'Order failed to process');
TraceReplay::ai()->setModel('anthropic');
TraceReplay::ai()->setTemperature(0.5);
TraceReplay::start()/end() for visibility:
public function handle() {
TraceReplay::start('Process Payment');
// Job logic
TraceReplay::end();
}
public function handle(OrderPlaced $event) {
TraceReplay::step('Order Placed', ['order_id' => $event->order->id]);
}
TraceReplay::replay() in tests to simulate production flows:
public function test_order_processing() {
$trace = TraceReplay::replay('http://example.com/api/orders/1');
$this->assertEquals('paid', $trace->steps[2]->output['status']);
}
Performance Overhead:
TraceReplay::auto(false) in production for non-critical paths or enable only for specific routes.Memory Leaks:
TraceReplay::step() with big arrays) can bloat storage.TraceReplay::mask():
TraceReplay::step('User Data', [
'email' => TraceReplay::mask($user->email),
'password' => '********'
]);
Replay Determinism:
time(), random_int()) break replay.TraceReplay::mock('time', fn() => 1625097600);
AI Rate Limits:
TraceReplay::ai()->cacheFor(minutes: 60);
Trace Not Showing?:
TraceReplay::start()/end() are called in the correct scope.storage/logs/trace-replay.log for initialization errors.trace-replay middleware is registered in app/Http/Kernel.php.Replay Failing:
TraceReplay::replay()->dryRun() to inspect the replay plan before execution.TraceReplay::replay()->missingMocks().UI Lag:
TraceReplay::ignore(function ($step) {
return in_array($step->name, ['Login', 'Payment']);
});
Custom Steps:
TraceReplay::extend():
TraceReplay::extend('db', function ($query) {
return $query->toSql() . ' [' . $query->getBindings() . ']';
});
Storage Backends:
TraceReplay::useStorage(\Iazaran\TraceReplay\Storage\RedisStorage::class);
AI Providers:
TraceReplay::ai()->addProvider('mistral', [
'url' => 'https://api.mistral.ai/v1',
'auth' => fn() => ['Bearer' => config('services.mistral.token')]
]);
Webhooks:
TraceReplay::onComplete(function ($trace) {
if ($trace->hasErrors()) {
Slack::alert("Trace failed: {$trace->id}");
}
});
trace_replay.sampling_rate (e.g., 10) to trace 10% of requests in production.trace_replay.retention_days to auto-purge old traces (default: 30).trace_replay.ignored_paths to exclude routes from tracing:
'ignored_paths' => [
'admin/*',
'api/webhooks/*'
],
How can I help you explore Laravel packages today?