Skip to content

Development Workflow

Jean-Marc Strauven edited this page Aug 1, 2025 · 2 revisions

Development Workflow

Learn how to integrate Laravel ChronoTrace into your development workflow for debugging, testing, and quality assurance.

Development Environment Setup

Initial Configuration

# Install ChronoTrace in development
composer require --dev grazulex/laravel-chronotrace
php artisan chronotrace:install

Development-Specific Configuration

# 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

Feature Development Workflow

1. Before Starting Development

# 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

2. During Feature Development

Record Baseline Traces

# 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 API Endpoints

# 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

Debug Complex Workflows

# 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

3. Analyzing Development Traces

Database Performance Analysis

# 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"

Cache Analysis

# 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"

External Service Integration

# 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])"

Test-Driven Development with ChronoTrace

1. Generate Tests from User Stories

# 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

2. Regression Testing

# 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

3. Integration Testing

# 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

Debugging Workflows

1. API Debugging

# 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

2. Performance Debugging

# 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

3. Error Debugging

# 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"

Code Review Process

1. Performance Review

#!/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

2. Integration Review

# 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])"
fi

Development Automation

1. Git Hooks Integration

pre-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"

2. CI/CD Integration

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/status

3. Local Development Scripts

dev-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

Best Practices

1. Trace Organization

# 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"

2. Development Environment Isolation

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'),
];

3. Team Collaboration

# 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/Team

Troubleshooting Development Issues

Common Development Problems

Middleware not capturing requests:

# Check middleware registration
php artisan chronotrace:test-middleware

# Verify configuration
php artisan config:show chronotrace

No database queries captured:

# Test database capture specifically
php artisan chronotrace:test-internal --with-db

Storage issues:

# Check storage configuration
php artisan chronotrace:diagnose

# Test storage write permissions
touch storage/chronotrace/test.txt && rm storage/chronotrace/test.txt

Next Steps

Clone this wiki locally