Laravel Chronotrace
Laravel Chronotrace stats
- Downloads
- 4
- Stars
- 6
- Open Issues
- 0
- Forks
- 0
Record and replay Laravel requests deterministically and generate tests from production traces.
Laravel ChronoTrace
β±οΈ Record and replay Laravel requests deterministically β capture all database queries, cache operations, HTTP calls, and queue jobs for debugging and analysis.
π Overview
Laravel ChronoTrace is a powerful debugging and monitoring tool for Laravel applications that allows you to:
- π― Capture HTTP requests and their complete execution context (DB queries, cache operations, external HTTP calls, queue jobs)
- π Replay traces to analyze what happened during specific requests
- π Debug production issues with comprehensive event logs
- π Monitor application performance and identify bottlenecks
Perfect for debugging hard-to-reproduce issues, performance analysis, and understanding complex application flows.
β¨ 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
π¦ Installation
composer require --dev grazulex/laravel-chronotrace
Requirements:
- PHP 8.3+
- Laravel 12.x
π Quick Start
1οΈβ£ Install and Configure
composer require --dev grazulex/laravel-chronotracephp artisan chronotrace:install
2οΈβ£ Configure Recording Mode
Edit config/chronotrace.php or set environment variables:
CHRONOTRACE_ENABLED=trueCHRONOTRACE_MODE=record_on_error # always | sample | record_on_error | targetedCHRONOTRACE_STORAGE=local # local | s3
3οΈβ£ Record Traces
For debugging real application issues:
# Record a specific endpointphp artisan chronotrace:record /api/users # Record with POST dataphp artisan chronotrace:record /api/users \ --method=POST \ --data='{"name":"John","email":"john@example.com"}' # Record with custom headersphp artisan chronotrace:record /api/protected \ --method=GET \ --headers='{"Authorization":"Bearer token123"}'
For testing ChronoTrace configuration:
# Test that ChronoTrace captures internal operationsphp artisan chronotrace:test-internal # Test specific operation typesphp artisan chronotrace:test-internal --with-db --with-cache
π‘ Key Difference:
chronotrace:recordcaptures real HTTP requests for debugging actual issues, whilechronotrace:test-internalvalidates that ChronoTrace is properly configured and working.
4οΈβ£ View Your Traces
# List all tracesphp artisan chronotrace:list # List with full trace IDsphp artisan chronotrace:list --full-id # Replay a specific trace (use ID from list command)php artisan chronotrace:replay abc12345-def6-7890-abcd-ef1234567890
5οΈβ£ Filter Events and Generate Tests
# View only database queriesphp artisan chronotrace:replay {trace-id} --db # View only cache operationsphp artisan chronotrace:replay {trace-id} --cache # View only HTTP requestsphp artisan chronotrace:replay {trace-id} --http # View only queue jobsphp artisan chronotrace:replay {trace-id} --jobs # View detailed information with context, headers, and contentphp artisan chronotrace:replay {trace-id} --detailed # Show SQL query bindings for debuggingphp artisan chronotrace:replay {trace-id} --db --bindings # Generate Pest tests from tracesphp artisan chronotrace:replay {trace-id} --generate-test # Generate tests in custom directoryphp artisan chronotrace:replay {trace-id} --generate-test --test-path=tests/Integration # Output as JSON for programmatic processingphp artisan chronotrace:replay {trace-id} --format=json
π§ Storage & Configuration
- Local Storage:
storage/chronotrace/{date}/{trace-id}/ - S3/Minio: Support for distributed setups with configurable buckets
- Automatic Cleanup: TTL-based purge policies (default: 15 days)
- Compression: Configurable compression for large traces
- PII Scrubbing: Automatic masking of sensitive fields
π What Gets Captured
Each trace includes comprehensive information:
=== TRACE INFORMATION ===π Trace ID: abc12345-def6-7890-abcd-ef1234567890π Timestamp: 2024-01-15 14:30:22π Environment: productionπ Request URL: https://app.example.com/api/usersπ Response Status: 200β±οΈ Duration: 245msπΎ Memory Usage: 18.45 KB === CAPTURED EVENTS ===π DATABASE EVENTS π Query: SELECT * FROM users WHERE active = ? (15ms) π Query: SELECT * FROM roles WHERE user_id IN (?, ?) (8ms) ποΈ CACHE EVENTS β Cache MISS: users:list (store: redis) πΎ Cache WRITE: users:list (store: redis) π HTTP EVENTS π€ HTTP Request: GET https://api.external.com/validation π₯ HTTP Response: 200 (1,234 bytes) βοΈ JOB EVENTS π Job STARTED: ProcessUserRegistration β
Job COMPLETED: ProcessUserRegistration
π§ Available Commands
Recording & Analysis Commands
chronotrace:recordβ Record real HTTP requests for debugging actual application issueschronotrace:listβ List stored traces with metadata and filtering optionschronotrace:replayβ Replay and analyze captured traces with advanced filtering and output formatschronotrace:purgeβ Remove old traces based on retention policy
Setup & Testing Commands
chronotrace:installβ Install and configure ChronoTrace middlewarechronotrace:test-internalβ Test ChronoTrace configuration with internal Laravel operationschronotrace:test-middlewareβ Test middleware installation and activationchronotrace:diagnoseβ Diagnose configuration and potential issues with comprehensive checks
Command Examples
# Installation and setupchronotrace:install --force # Validate ChronoTrace is workingchronotrace:test-internal --with-db --with-cache # Record real application traceschronotrace:record /api/users --method=GETchronotrace:record /checkout --method=POST --data='{"cart_id": 123}'chronotrace:record /api/protected --headers='{"Authorization":"Bearer token"}' # Advanced recording with timeoutchronotrace:record /api/slow-endpoint --timeout=60 # List and analyze traceschronotrace:list --limit=10 --full-idchronotrace:replay {trace-id} --db --cache --bindingschronotrace:replay {trace-id} --detailed --context --headerschronotrace:replay {trace-id} --generate-test --test-path=tests/Integration # Output in different formatschronotrace:replay {trace-id} --format=jsonchronotrace:replay {trace-id} --format=raw # Diagnostics and testingchronotrace:diagnosechronotrace:test-middleware # Test internal operations when chronotrace:record doesn't capture internal eventschronotrace:test-internal --with-db --with-cache --with-eventschronotrace:test-internal --with-db # Test only database operations # Maintenance and cleanupchronotrace:purge --days=7 --confirm
π Use Cases
- Bug Reproduction β No more βcanβt reproduce locallyβ issues
- Test Generation β Build realistic tests from production data
- Performance Audits β Find slow queries, N+1s and cache misses
- Configuration Validation β Diagnose setup issues with built-in tools
- Onboarding β Help new devs understand complex flows via execution graphs
π Security & Privacy
- PII scrubbing by default (configurable fields)
- Trace encryption at rest
- Trace TTL & purge policies
- Audit log of trace access
π€ Contributing
We welcome contributions! See CONTRIBUTING.md for details.
π Documentation
Complete documentation is available in the GitHub Wiki:
- π¦ Installation Guide - Step-by-step installation instructions
- βοΈ Configuration Guide - Complete configuration reference
- π§ Commands Reference - Detailed guide to all commands
- π― Choosing the Right Command - When to use
recordvstest-internal - π§ͺ Testing Internal Operations - Validate ChronoTrace configuration
- π‘ Examples & Workflows - Practical usage examples and common workflows
- π Security & Storage - Security features and storage options
- π Troubleshooting - Common issues and solutions
Laravel ChronoTrace is open-sourced software licensed under the MIT license.
Made with β€οΈ for the Laravel community