-
-
Notifications
You must be signed in to change notification settings - Fork 1
Your First Trace
A step-by-step walkthrough to capture, analyze, and understand your first ChronoTrace. Perfect for getting familiar with the basic workflow.
- How to capture your first trace
- How to analyze trace output
- How to identify issues in traces
- Basic filtering and analysis techniques
Prerequisites: ChronoTrace should be installed and configured.
First, let's make sure ChronoTrace is working correctly:
# Check if ChronoTrace is properly installed
php artisan chronotrace:diagnoseExpected output:
β
ChronoTrace Configuration
Enabled: Yes
Mode: record_on_error
Storage: local (/path/to/storage/chronotrace)
β
Storage
Writable: Yes
Free Space: 15.2 GB
If you see any β errors, check the Troubleshooting Guide.
For this tutorial, we'll use "always" mode to capture everything:
# Temporarily enable full recording (in .env)
CHRONOTRACE_MODE=always
CHRONOTRACE_ENABLED=true
# Clear config cache to apply changes
php artisan config:clearLet's create a simple test request that we can trace. You have several options:
# Generate a test trace with sample events
php artisan chronotrace:test-internal# Make a request to your application
curl -X GET http://localhost:8000/
# Or make a POST request with data
curl -X POST http://localhost:8000/api/users \
-H "Content-Type: application/json" \
-d '{"name":"John Doe","email":"john@example.com"}'Simply visit your application in a browser and navigate to any page.
Now let's see what traces were captured:
# List recent traces
php artisan chronotrace:listYou should see output like this:
ββββββββββββββ¬ββββββββββββββββββββββ¬βββββββββ¬βββββββββββ¬ββββββββββββββββββββββββββ¬βββββββββββ
β Trace ID β Timestamp β Method β Status β Route β Duration β
ββββββββββββββΌββββββββββββββββββββββΌβββββββββΌβββββββββββΌββββββββββββββββββββββββββΌβββββββββββ€
β abc123... β 2024-08-06 14:30:15 β GET β 200 β / β 89ms β
β def456... β 2024-08-06 14:28:42 β POST β 201 β api/users β 156ms β
ββββββββββββββ΄ββββββββββββββββββββββ΄βββββββββ΄βββββββββββ΄ββββββββββββββββββββββββββ΄βββββββββββ
Found 2 traces.
Understanding the output:
- Trace ID: Unique identifier for this trace
- Timestamp: When the request was made
- Method: HTTP method (GET, POST, PUT, DELETE)
- Status: HTTP response code
- Route: The route that was accessed
- Duration: How long the request took
Now let's examine a trace in detail. Copy a Trace ID from the list and replay it:
# Replace 'abc123...' with your actual Trace ID
php artisan chronotrace:replay abc123def456789The trace starts with basic request information:
ββ REQUEST INFORMATION βββββββββββββββββββββββββββββββββββββββββ
β Trace ID: abc123def456789 β
β Method: GET / β
β Status: 200 OK β
β Duration: 89ms β
β Memory: 8.2MB β
β Timestamp: 2024-08-06 14:30:15 UTC β
β User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) β
β IP Address: 127.0.0.1 β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Key information:
- Duration: Total request processing time
- Memory: Peak memory usage during request
- Status: HTTP response code (200 = success)
Next, you'll see events organized by type and time:
ββ DATABASE EVENTS (3 queries, 12ms total) ββββββββββββββββββββ
β [+0ms] SELECT * FROM users WHERE email = ? ['john@example.com'] (4ms)
β Connection: mysql, Rows: 1
β
β [+15ms] SELECT * FROM user_profiles WHERE user_id = ? [123] (3ms)
β Connection: mysql, Rows: 1
β
β [+45ms] UPDATE users SET last_login = ? WHERE id = ? ['2024-08-06 14:30:15', 123] (5ms)
β Connection: mysql, Affected: 1
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Understanding database events:
- [+0ms]: Time offset from request start
- SQL Query: The actual query executed
- Bindings: Parameter values (in brackets)
- Duration: Time this query took
- Metadata: Connection, rows returned/affected
ββ CACHE EVENTS (2 operations) ββββββββββββββββββββββββββββββββ
β [+25ms] GET user:123:profile (HIT)
β Store: redis, TTL: 3600s
β
β [+67ms] SET user:123:last_activity (TTL: 3600s)
β Store: redis, Size: 45 bytes
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Understanding cache events:
- GET/SET/FORGET: Cache operation type
- HIT/MISS: Whether cache lookup succeeded
- TTL: Time-to-live in seconds
- Size: Data size for SET operations
ββ HTTP EVENTS (1 request) βββββββββββββββββββββββββββββββββββββ
β [+78ms] POST https://api.example.com/webhook (45ms)
β Status: 200 OK
β Request Size: 234 bytes
β Response Size: 89 bytes
β Headers: Content-Type: application/json
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Understanding HTTP events:
- URL: External API called
- Duration: Time the external request took
- Status: Response code from external API
- Sizes: Request and response payload sizes
Let's focus on specific types of events:
php artisan chronotrace:replay abc123def456789 --filter=databaseThis shows only SQL queries, making it easier to identify database performance issues.
php artisan chronotrace:replay abc123def456789 --filter=httpPerfect for debugging external API integration issues.
php artisan chronotrace:replay abc123def456789 --filter=database,httpCombines database and HTTP events while hiding cache operations.
php artisan chronotrace:replay abc123def456789 --min-duration=10Shows only events that took longer than 10ms.
Let's intentionally create an error to see how ChronoTrace captures failures:
# Request a non-existent endpoint
curl -X GET http://localhost:8000/non-existent-pageCreate a test route that throws an exception:
// In routes/web.php
Route::get('/test-error', function () {
throw new \Exception('This is a test error for ChronoTrace');
});Then visit: http://localhost:8000/test-error
# List traces, look for 500 status
php artisan chronotrace:list --status=error
# Replay the error trace
php artisan chronotrace:replay error-trace-idError traces show:
- Complete execution flow up to the error
- The exact point where the error occurred
- Stack trace and error message
- All database queries before the failure
- External API calls that might have caused issues
Let's create a slow request to practice performance analysis:
// In routes/web.php
Route::get('/test-slow', function () {
// Simulate slow database query
sleep(1);
// Simulate external API call
$response = Http::timeout(30)->get('https://httpbin.org/delay/2');
return response()->json(['status' => 'completed']);
});# Make the slow request
curl -X GET http://localhost:8000/test-slow
# Find slow traces (>1000ms)
php artisan chronotrace:list --min-duration=1000
# Analyze the slow trace
php artisan chronotrace:replay slow-trace-idLook for:
- Long-running database queries
- Slow external HTTP calls
- Memory usage spikes
- Overall request timeline
After testing, let's clean up:
# Remove test traces
php artisan chronotrace:purge --days=0
# Reset to production-safe mode
CHRONOTRACE_MODE=record_on_error
# Clear config cache
php artisan config:clearCongratulations! You've successfully:
- β Captured traces using different methods
- β Listed and filtered traces by various criteria
- β Replayed traces to see detailed execution flow
- β Analyzed different event types (database, cache, HTTP)
- β Debugged errors with complete context
- β Identified performance issues in slow requests
- β Used filtering to focus on specific problems
Now that you understand the basics:
- Basic Usage - Learn more advanced workflows
- Event Capturing - Configure what events to capture
- Configuration - Customize ChronoTrace for your needs
- Commands - Explore all available commands
When you're ready for production:
# Set production-safe configuration
CHRONOTRACE_MODE=record_on_error
CHRONOTRACE_SAMPLE_RATE=0.001
CHRONOTRACE_ASYNC_STORAGE=trueCheck the Production Monitoring guide for best practices.
- Bookmark useful traces: Note trace IDs of important requests for future reference
- Use targeted recording: Focus on specific routes during debugging
- Regular cleanup: Set up automatic purging to manage storage
- Filter smartly: Use event filtering to reduce noise in complex traces
- Monitor performance: Watch for trends in request duration and memory usage
Ready for more advanced usage? Check out our example scenarios for real-world debugging techniques!
- 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