-
-
Notifications
You must be signed in to change notification settings - Fork 1
Development Workflow
Jean-Marc Strauven edited this page Aug 1, 2025
·
2 revisions
Learn how to integrate Laravel ChronoTrace into your development workflow for debugging, testing, and quality assurance.
# Install ChronoTrace in development
composer require --dev grazulex/laravel-chronotrace
php artisan chronotrace:install# Development .env settings
CHRONOTRACE_ENABLED=true
CHRONOTRACE_MODE=always
CHRONOTRACE_STORAGE=local
CHRONOTRACE_RETENTION_DAYS=7
CHRONOTRACE_DEBUG=true
# Capture everything for debugging
CHRONOTRACE_CAPTURE_DATABASE=true
CHRONOTRACE_CAPTURE_CACHE=true
CHRONOTRACE_CAPTURE_HTTP=true
CHRONOTRACE_CAPTURE_JOBS=true
CHRONOTRACE_CAPTURE_EVENTS=true
# Use synchronous storage for immediate feedback
CHRONOTRACE_ASYNC_STORAGE=false# Validate your ChronoTrace setup
php artisan chronotrace:diagnose
# Clean up old traces
php artisan chronotrace:purge --days=1 --confirm
# Test middleware
php artisan chronotrace:test-middleware# Record current behavior before changes
php artisan chronotrace:record /api/feature-endpoint \
--method=GET \
--headers='{"Authorization":"Bearer dev-token"}'
# Note the trace ID for later comparison
php artisan chronotrace:list --limit=1 --full-id# Test GET requests
php artisan chronotrace:record /api/users
php artisan chronotrace:record /api/users/123
# Test POST requests with data
php artisan chronotrace:record /api/users \
--method=POST \
--data='{"name":"Test User","email":"test@example.com"}'
# Test PUT/PATCH requests
php artisan chronotrace:record /api/users/123 \
--method=PUT \
--data='{"name":"Updated Name"}'
# Test DELETE requests
php artisan chronotrace:record /api/users/123 \
--method=DELETE# Record a complex business process
php artisan chronotrace:record /orders/checkout \
--method=POST \
--data='{
"items": [{"id": 1, "quantity": 2}],
"payment": {"method": "credit_card"},
"shipping": {"address": "123 Main St"}
}' \
--headers='{"Authorization":"Bearer test-token"}'
# Analyze the full workflow
TRACE_ID=$(php artisan chronotrace:list --limit=1 --full-id | grep "β" | head -1 | awk '{print $2}')
php artisan chronotrace:replay $TRACE_ID --detailed# Check for N+1 queries
php artisan chronotrace:replay {trace-id} --db
# View SQL bindings for debugging
php artisan chronotrace:replay {trace-id} --db --bindings
# Look for slow queries
php artisan chronotrace:replay {trace-id} --db | grep -E "[0-9]{3,}ms"# Check cache efficiency
php artisan chronotrace:replay {trace-id} --cache
# Look for cache misses that could be optimized
php artisan chronotrace:replay {trace-id} --cache | grep "MISS"# Monitor API calls to external services
php artisan chronotrace:replay {trace-id} --http
# Check for failed external requests
php artisan chronotrace:replay {trace-id} --http | grep -E "(Failed|4[0-9][0-9]|5[0-9][0-9])"# Record user workflow
php artisan chronotrace:record /complete-user-registration \
--method=POST \
--data='{"email":"user@example.com","password":"password123"}'
# Generate test from the workflow
php artisan chronotrace:replay {trace-id} --generate-test --test-path=tests/Feature
# Review and customize the generated test
cat tests/Feature/ChronoTrace_{trace-id}_Test.php# Create regression tests for bug fixes
php artisan chronotrace:record /bug-endpoint-before-fix
# ... fix the bug ...
php artisan chronotrace:record /bug-endpoint-after-fix
# Generate test that validates the fix
php artisan chronotrace:replay {after-fix-trace-id} --generate-test --test-path=tests/Regression# Test complex integrations
php artisan chronotrace:record /api/payment/process \
--method=POST \
--data='{"amount": 100, "method": "stripe"}' \
--headers='{"Authorization":"Bearer test-token"}'
# Generate integration test
php artisan chronotrace:replay {trace-id} --generate-test --test-path=tests/Integration# Record API request with full detail
php artisan chronotrace:record /api/problematic-endpoint \
--method=POST \
--data='{"test": "data"}' \
--headers='{"Content-Type":"application/json","Authorization":"Bearer token"}'
# Analyze with maximum detail
php artisan chronotrace:replay {trace-id} --detailed --context --headers --content --bindings# Record slow endpoint
php artisan chronotrace:record /slow-endpoint
# Get performance metrics
TRACE_ID=$(php artisan chronotrace:list --limit=1 --full-id | grep "β" | head -1 | awk '{print $2}')
echo "Performance Analysis for: $TRACE_ID"
# Check execution time
php artisan chronotrace:replay $TRACE_ID | grep "Duration"
# Analyze database queries
php artisan chronotrace:replay $TRACE_ID --db | grep -E "[0-9]{3,}ms"
# Check cache performance
php artisan chronotrace:replay $TRACE_ID --cache# Record failing request
php artisan chronotrace:record /failing-endpoint \
--method=POST \
--data='{"invalid": "data"}'
# Analyze the error
php artisan chronotrace:replay {trace-id} --detailed
# Check logs related to the trace
php artisan chronotrace:replay {trace-id} | grep -A5 -B5 "error\|exception\|fail"#!/bin/bash
# performance-review.sh - Check performance of new features
FEATURE_ENDPOINTS=(
"/api/new-feature"
"/api/updated-feature"
)
echo "π Performance Review for New Features"
echo "====================================="
for endpoint in "${FEATURE_ENDPOINTS[@]}"; do
echo "Testing: $endpoint"
# Record endpoint
php artisan chronotrace:record "$endpoint"
TRACE_ID=$(php artisan chronotrace:list --limit=1 --full-id | grep "β" | head -1 | awk '{print $2}')
# Get performance metrics
DURATION=$(php artisan chronotrace:replay $TRACE_ID | grep "Duration:" | awk '{print $3}')
MEMORY=$(php artisan chronotrace:replay $TRACE_ID | grep "Memory:" | awk '{print $3}')
echo " β±οΈ Duration: $DURATION"
echo " πΎ Memory: $MEMORY"
# Count database queries
DB_QUERIES=$(php artisan chronotrace:replay $TRACE_ID --db | grep -c "Query:")
echo " π DB Queries: $DB_QUERIES"
# Performance warnings
if [[ $DURATION =~ ([0-9]+)ms && ${BASH_REMATCH[1]} -gt 1000 ]]; then
echo " β οΈ WARNING: Response time over 1 second"
fi
if [[ $DB_QUERIES -gt 10 ]]; then
echo " β οΈ WARNING: High number of database queries - check for N+1"
fi
echo ""
done# Check external service integrations
php artisan chronotrace:record /api/feature-with-external-calls
TRACE_ID=$(php artisan chronotrace:list --limit=1 --full-id | grep "β" | head -1 | awk '{print $2}')
echo "π External Service Integration Review"
echo "====================================="
# Check HTTP calls
HTTP_CALLS=$(php artisan chronotrace:replay $TRACE_ID --http | grep -c "HTTP Request:")
echo "External HTTP calls: $HTTP_CALLS"
# Check for failed calls
FAILED_CALLS=$(php artisan chronotrace:replay $TRACE_ID --http | grep -c -E "(Failed|[45][0-9][0-9])")
if [ $FAILED_CALLS -gt 0 ]; then
echo "β οΈ Failed external calls detected:"
php artisan chronotrace:replay $TRACE_ID --http | grep -E "(Failed|[45][0-9][0-9])"
fipre-commit hook (.git/hooks/pre-commit):
#!/bin/bash
# Pre-commit hook to check critical endpoints
echo "π Running ChronoTrace health check..."
# Test critical endpoints
CRITICAL_ENDPOINTS=(
"/health"
"/api/status"
)
for endpoint in "${CRITICAL_ENDPOINTS[@]}"; do
if ! php artisan chronotrace:record "$endpoint" > /dev/null 2>&1; then
echo "β Critical endpoint $endpoint is failing"
exit 1
fi
done
echo "β
All critical endpoints are healthy"GitHub Actions example (.github/workflows/chronotrace.yml):
name: ChronoTrace Health Check
on: [push, pull_request]
jobs:
chronotrace-health:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
- name: Install dependencies
run: composer install --no-dev --optimize-autoloader
- name: Setup application
run: |
php artisan key:generate
php artisan migrate
- name: Test ChronoTrace Configuration
run: |
php artisan chronotrace:diagnose
php artisan chronotrace:test-internal
- name: Test Critical Endpoints
run: |
php artisan chronotrace:record /health
php artisan chronotrace:record /api/statusdev-tools.sh:
#!/bin/bash
# Development utility scripts for ChronoTrace
case "$1" in
"quick-test")
echo "π§ͺ Quick ChronoTrace Test"
php artisan chronotrace:test-internal --with-db --with-cache
;;
"analyze-last")
echo "π Analyzing Last Trace"
TRACE_ID=$(php artisan chronotrace:list --limit=1 --full-id | grep "β" | head -1 | awk '{print $2}')
php artisan chronotrace:replay $TRACE_ID --detailed
;;
"performance-check")
echo "β‘ Performance Check"
TRACE_ID=$(php artisan chronotrace:list --limit=1 --full-id | grep "β" | head -1 | awk '{print $2}')
php artisan chronotrace:replay $TRACE_ID --db | grep -E "[0-9]{3,}ms"
;;
"cleanup")
echo "π§Ή Cleaning up old traces"
php artisan chronotrace:purge --days=3 --confirm
;;
*)
echo "Usage: $0 {quick-test|analyze-last|performance-check|cleanup}"
;;
esac# Use meaningful trace names for complex workflows
php artisan chronotrace:record /user-registration-flow \
--name="User Registration Complete Workflow"
# Record traces for specific features
php artisan chronotrace:record /api/payment/checkout \
--name="Payment Checkout Process"config/chronotrace.php:
return [
'enabled' => env('CHRONOTRACE_ENABLED', app()->environment('local')),
// Different settings per environment
'storage' => app()->environment('local') ? 'local' : 's3',
'retention' => [
'days' => app()->environment('local') ? 3 : 30,
],
// More verbose logging in development
'debug' => app()->environment('local'),
];# Share traces with team members
php artisan chronotrace:replay {trace-id} --format=json > trace-analysis.json
# Export for debugging sessions
php artisan chronotrace:replay {trace-id} --detailed > debug-session.txt
# Generate shareable test
php artisan chronotrace:replay {trace-id} --generate-test --test-path=tests/TeamMiddleware not capturing requests:
# Check middleware registration
php artisan chronotrace:test-middleware
# Verify configuration
php artisan config:show chronotraceNo database queries captured:
# Test database capture specifically
php artisan chronotrace:test-internal --with-dbStorage issues:
# Check storage configuration
php artisan chronotrace:diagnose
# Test storage write permissions
touch storage/chronotrace/test.txt && rm storage/chronotrace/test.txt- 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