Laravel ChronoTrace
The Laravel ChronoTrace package enables you to record and replay Laravel requests deterministically and generate tests from production traces. This package can help you trace external HTTP requests made during execution, including request/response details, status codes, connection issues, and more. It also tracks database queries, cache events, queue jobs, and custom events.
After a trace is captured, you can replay it to show all the information gathered (which is configurable) during the trace:
=== TRACE INFORMATION ===π Trace ID: a1b2c3d4-e5f6-7890-abcd-ef1234567890π Timestamp: 2024-01-15 14:30:22π Environment: localπ Request URL: http://localhost:8000/api/usersπ Response Status: 200β±οΈ Duration: 245msπΎ Memory Usage: 18.45 KB === CAPTURED EVENTS ===π DATABASE EVENTS π [14:30:22.123] Query: SELECT * FROM users WHERE active = ? (15ms on mysql) π [14:30:22.145] Query: SELECT * FROM roles WHERE user_id IN (?, ?, ?) (8ms on mysql) ποΈ CACHE EVENTS β [14:30:22.120] Cache MISS: users:list (store: redis) πΎ [14:30:22.150] Cache WRITE: users:list (store: redis) π HTTP EVENTS π€ [14:30:22.200] HTTP Request: GET https://api.external.com/validation π₯ [14:30:22.230] HTTP Response: GET https://api.external.com/validation β 200 π EVENTS SUMMARY π Database events: 2 ποΈ Cache events: 2 π HTTP events: 2 βοΈ Job events: 0 π Total events: 6
Another interesting feature is generating a test from a specific trace that you've recordedβrecording frequency can be configured as always, sample rate, error-only, etc. Once you have a trace you want to convert into a test, you can run the replay command with the --generate-test flag:
php artisan chronotrace:replay a1b2c3d4 \--generate-test \--test-path=tests/Integration
Main Features
- Smart Recording β Multiple recording modes: always, sample rate, error-only, or targeted routes
- Comprehensive Event Capture β Database queries, cache operations, HTTP requests, queue jobs, and custom events
- Detailed Replay β View complete execution flow with timestamps and performance metrics
- Flexible Filtering β Focus on specific event types (DB, cache, HTTP, jobs) during analysis
- Multiple Storage Options β Local storage, S3, or custom storage adapters
- PII Scrubbing β Automatically mask sensitive data (passwords, tokens, emails, etc.)
- Async Storage β Queue-based storage for minimal performance impact
- Automatic Cleanup β Configurable retention policies and automatic purging
I would recommend checking out the Basic Usage examples for real-world ideas on how to use this package. The usage examples illustrate common workflows such as development, bug investigation, and more.
You can get started with this package on GitHub: Grazulex/laravel-chronotrace.
To install this in your application (Laravel v12.x+ and PHP 8.3+) with Composer, require it as a development dependency and run the install command:
composer require --dev grazulex/laravel-chronotracephp artisan chronotrace:install