-
-
Notifications
You must be signed in to change notification settings - Fork 1
Recording Modes
ChronoTrace offers flexible recording modes to suit different environments and use cases. Choose the right mode to balance debugging capabilities with performance and storage requirements.
Recording modes determine when ChronoTrace captures traces:
| Mode | Best For | Captures | Performance Impact | Storage Usage |
|---|---|---|---|---|
always |
Development | Every request | High | Very High |
sample |
Staging/Testing | Random percentage | Medium | Medium |
record_on_error |
Production | Errors + samples | Low | Low |
targeted |
Debugging | Specific routes/conditions | Very Low | Very Low |
Set the recording mode in your .env file:
CHRONOTRACE_MODE=record_on_error
CHRONOTRACE_SAMPLE_RATE=0.001Or in the configuration file:
// config/chronotrace.php
'mode' => env('CHRONOTRACE_MODE', 'record_on_error'),
'sample_rate' => env('CHRONOTRACE_SAMPLE_RATE', 0.001),Perfect for development environments where you want complete visibility.
CHRONOTRACE_MODE=always
CHRONOTRACE_ENABLED=true- β Records every single request
- β Captures all events (DB, cache, HTTP, jobs)
- β No sampling or filtering
- β Immediate trace availability
# Development debugging
- Understanding application flow
- Learning how features work
- Comprehensive testing
- Performance profiling
# Team collaboration
- Sharing exact request traces
- Documenting complex workflows
- Code review assistance$ php artisan chronotrace:list
ββββββββββββββ¬ββββββββββββββββββββββ¬βββββββββ¬βββββββββββ¬ββββββββββββββββββ¬βββββββββββ
β Trace ID β Timestamp β Method β Status β Route β Duration β
ββββββββββββββΌββββββββββββββββββββββΌβββββββββΌβββββββββββΌββββββββββββββββββΌβββββββββββ€
β req_001 β 2024-08-06 14:30:15 β GET β 200 β / β 45ms β
β req_002 β 2024-08-06 14:30:16 β GET β 200 β /api/users β 89ms β
β req_003 β 2024-08-06 14:30:17 β POST β 201 β /api/users β 156ms β
β req_004 β 2024-08-06 14:30:18 β GET β 200 β /dashboard β 234ms β
ββββββββββββββ΄ββββββββββββββββββββββ΄βββββββββ΄βββββββββββ΄ββββββββββββββββββ΄βββββββββββIdeal for staging environments and performance monitoring.
CHRONOTRACE_MODE=sample
CHRONOTRACE_SAMPLE_RATE=0.1 # 10% of requests// config/chronotrace.php
'sampling' => [
'base_rate' => 0.05, // 5% base sampling
'error_rate' => 1.0, // Always capture errors
'slow_request_threshold' => 1000, // Requests > 1s
'slow_request_rate' => 0.5, // 50% of slow requests
'user_based_sampling' => [
'admin_users' => 0.2, // 20% for admins
'beta_users' => 0.15, // 15% for beta testers
'regular_users' => 0.02, // 2% for regular users
],
],- β Records random percentage of requests
- β Always captures errors regardless of sample rate
- β Can prioritize slow requests
- β Configurable per user type
# Staging environment
- Load testing analysis
- Performance trend monitoring
- Feature rollout monitoring
- Integration testing
# Pre-production validation
- Representative traffic sampling
- Performance baseline establishment
- Error rate monitoring| Environment | Sample Rate | Rationale |
|---|---|---|
| Local Development | 1.0 (100%) | Full visibility needed |
| Staging | 0.1 (10%) | Representative sampling |
| Load Testing | 0.05 (5%) | Reduce overhead during tests |
| Pre-production | 0.02 (2%) | Light monitoring |
// High traffic (>10k requests/day)
'sample_rate' => 0.001, // 0.1%
// Medium traffic (1k-10k requests/day)
'sample_rate' => 0.01, // 1%
// Low traffic (<1k requests/day)
'sample_rate' => 0.1, // 10%Recommended for production environments.
CHRONOTRACE_MODE=record_on_error
CHRONOTRACE_SAMPLE_RATE=0.001 # 0.1% of successful requests- β Always records errors (4xx, 5xx status codes)
- β Records small sample of successful requests
- β Minimal performance impact
- β Storage-efficient
// Automatically captures these scenarios:
- HTTP 400-499 (Client errors)
- HTTP 500-599 (Server errors)
- PHP exceptions
- Database query failures
- External API failures
- Queue job failures// config/chronotrace.php
'error_conditions' => [
'status_codes' => [400, 401, 403, 404, 422, 500, 502, 503],
'slow_requests' => 5000, // > 5 seconds
'memory_threshold' => 128 * 1024 * 1024, // > 128MB
'custom_conditions' => [
'failed_payment' => function ($request, $response) {
return $request->is('api/payments/*') && $response->status() >= 400;
},
],
],# Production monitoring
- Error tracking and debugging
- Performance issue detection
- API failure monitoring
- Payment processing errors
# Incident response
- Post-mortem analysis
- Root cause investigation
- Error reproduction
- Timeline reconstructionreturn [
'mode' => 'record_on_error',
'sample_rate' => 0.0005, // 0.05% of successful requests
'capture' => [
'database' => true,
'http' => true,
'jobs' => true,
'cache' => false, // Reduce noise
'events' => false, // Reduce noise
],
'retention_days' => 7, // Short retention
'async_storage' => true, // Performance
];Perfect for debugging specific features or routes.
CHRONOTRACE_MODE=targeted// config/chronotrace.php
'targeted_routes' => [
'api/orders/*',
'api/payments/*',
'checkout/*',
'admin/users/*',
],// config/chronotrace.php
'targeted_conditions' => [
// Specific users
'user_ids' => [123, 456, 789],
// IP addresses
'ip_addresses' => ['192.168.1.100', '10.0.0.50'],
// User agents
'user_agents' => ['TestRunner/*', 'Postman/*'],
// Custom headers
'headers' => [
'X-Debug-Session' => 'active',
'X-Feature-Flag' => 'new-checkout',
],
// Query parameters
'query_params' => [
'debug' => 'true',
'trace' => 'enabled',
],
],// Enable targeting for specific sessions
Route::middleware(['chronotrace.targeted'])->group(function () {
Route::post('/api/orders', [OrderController::class, 'store']);
Route::get('/api/orders/{order}', [OrderController::class, 'show']);
});# Feature debugging
- New feature development
- Bug reproduction
- Performance optimization
- Integration testing
# User-specific issues
- Customer support debugging
- VIP user monitoring
- Beta feature testing
- A/B testing analysis# Start targeted recording for specific user
php artisan chronotrace:target --user-id=123 --duration=1h
# Target specific routes temporarily
php artisan chronotrace:target --routes="api/orders/*" --duration=30m
# Target by IP address
php artisan chronotrace:target --ip="192.168.1.100" --duration=15m# Temporarily enable full recording
php artisan chronotrace:record --mode=always --duration=5m
# Switch to error-only mode
php artisan chronotrace:mode record_on_error
# Enable targeted recording
php artisan chronotrace:mode targeted --routes="api/payments/*"// In your application code
use Grazulex\LaravelChronotrace\Facades\ChronoTrace;
// Temporarily change mode
ChronoTrace::setMode('always')->for(minutes: 5);
// Enable for specific request
ChronoTrace::enableForCurrentRequest();
// Force recording regardless of mode
ChronoTrace::forceRecord();// config/chronotrace.php
'mode' => match(app()->environment()) {
'local' => 'always',
'testing' => 'sample',
'staging' => 'sample',
'production' => 'record_on_error',
default => 'record_on_error',
},| Mode | CPU Overhead | Memory Overhead | Storage/Day |
|---|---|---|---|
always |
~5-15ms | ~2-5MB | ~500MB-2GB |
sample (10%) |
~0.5-1.5ms | ~0.2-0.5MB | ~50-200MB |
record_on_error |
~0.1-0.5ms | ~0.1-0.2MB | ~5-50MB |
targeted |
~0.05-0.2ms | ~0.05-0.1MB | ~1-10MB |
Note: Actual overhead depends on application complexity and event types captured.
// Reduce overhead in any mode
'capture' => [
'database' => true, // Essential
'http' => true, // Important for APIs
'jobs' => true, // Important for async work
'cache' => false, // Often noisy
'events' => false, // Very verbose
],
// Use async storage
'async_storage' => true,
'queue_connection' => 'redis',
// Limit trace size
'memory' => [
'max_trace_size' => 5 * 1024 * 1024, // 5MB limit
],- β Developing new features
- β Learning application behavior
- β Debugging complex issues
- β Creating documentation
- β Never in production
- β Staging environment testing
- β Performance monitoring
- β Load testing analysis
- β Feature rollout monitoring
- β Production monitoring
- β Error tracking
- β Incident response
- β Minimal overhead required
- β Debugging specific features
- β Customer support issues
- β Performance optimization
- β Beta testing
# Trace volume and coverage
php artisan chronotrace:stats --mode-effectiveness
# Storage usage by mode
php artisan chronotrace:diagnose --storage --mode-breakdown
# Performance impact analysis
php artisan chronotrace:performance --compare-modes# Daily metrics
- Total requests: 10,000
- Traces captured: 50 (0.5%)
- Errors captured: 15/15 (100%)
- Storage used: 25MB
- Average overhead: 0.2ms// config/chronotrace.php
'multi_mode' => [
'api_routes' => 'record_on_error',
'admin_routes' => 'sample',
'payment_routes' => 'always', // Critical flows
'public_routes' => 'targeted',
],'mode_resolver' => function ($request) {
if ($request->header('X-Debug-Mode')) {
return 'always';
}
if ($request->is('api/payments/*')) {
return 'record_on_error';
}
return 'sample';
},- Configuration - Complete configuration options
- Commands - Mode control commands
- Production Monitoring - Production mode best practices
Need help choosing the right mode? Check our Configuration Examples for ready-to-use configurations for common scenarios.
- Getting Started - Install and configure ChronoTrace
- Examples - Real-world debugging scenarios
- Production Guide - Deploy safely in production
- Troubleshooting - Solve common issues
| Section | Page | Description |
|---|---|---|
| π Basics | Your First Trace | Step-by-step beginner guide |
| ποΈ Config | Recording Modes | Choose when to record traces |
| π‘οΈ Security | Security & PII | Protect sensitive data |
| π§ Tools | Commands | Complete command reference |
- π¬ GitHub Discussions - Community support
- π Report Issues - Bug reports & feature requests
- π§ Contact - Direct support
- π‘ Feature Requests - Suggest improvements
ChronoTrace helps Laravel developers debug applications faster with intelligent request tracing.
Made with β€οΈ by Grazulex β’ Documentation updated August 2024