-
-
Notifications
You must be signed in to change notification settings - Fork 1
Testing Internal Operations
This guide explains how to test ChronoTrace with internal Laravel operations using the chronotrace:test-internal command.
The chronotrace:test-internal command addresses a common limitation where chronotrace:record primarily captures external HTTP events. This command allows you to test ChronoTrace's ability to capture internal Laravel operations like database queries, cache operations, and custom events.
- Purpose: Capture real HTTP requests in production/staging
- Data: Genuine user requests with actual business logic
- Use when: Debugging real bugs, analyzing user workflows, production monitoring
-
Example:
chronotrace:record /api/orders/123captures a real order request
- Purpose: Validate that ChronoTrace is properly configured and working
- Data: Artificial test operations to verify capture mechanisms
- Use when: Installation validation, testing after config changes, CI/CD
-
Example:
chronotrace:test-internal --with-dbtests database event capture
Key Difference: record captures real application behavior, while test-internal validates that ChronoTrace itself is working correctly.
php artisan chronotrace:test-internal [options]-
--with-db: Include database operation tests -
--with-cache: Include cache operation tests -
--with-events: Include custom event tests
Test all internal operations:
php artisan chronotrace:test-internal --with-db --with-cache --with-eventsTest only database operations:
php artisan chronotrace:test-internal --with-dbTest cache and events:
php artisan chronotrace:test-internal --with-cache --with-events- Creates a test table
- Performs INSERT, UPDATE, SELECT, and DELETE operations
- Tests both Eloquent ORM and Query Builder operations
- Sets cache values with different drivers
- Retrieves cached data
- Tests cache invalidation
- Note: May fail in minimal environments without cache table setup
- Fires custom Laravel events
- Tests event listener registration
- Validates event data capture
When you run the command, you'll see:
- Trace ID Generation: A unique identifier for this test session
- Operation Results: Success/failure status for each tested operation
- ChronoTrace Activity: Debug information showing what ChronoTrace captured
- Usage Instructions: How to replay or generate tests from the captured trace
Example output:
π§ͺ Testing ChronoTrace with internal Laravel operations...
π Starting trace: ct_neOhAT0HI3v0a8Rg_1754050787
ποΈ Testing database operations...
πΎ Testing cache operations...
π‘ Testing custom events...
β
Internal operations test completed!
π Trace ID: ct_neOhAT0HI3v0a8Rg_1754050787
π‘ Use: php artisan chronotrace:replay ct_neOhAT0HI3v0a8Rg_1754050787 to view the captured trace
π§ͺ Use: php artisan chronotrace:replay ct_neOhAT0HI3v0a8Rg_1754050787 --generate-test to create a test file
The command tests various database operations:
// Table creation
Schema::create('chronotrace_test', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->timestamps();
});
// Insert operations
DB::table('chronotrace_test')->insert(['name' => 'Test Item']);
// Query operations
DB::table('chronotrace_test')->where('name', 'Test Item')->first();
// Update operations
DB::table('chronotrace_test')->where('id', 1)->update(['name' => 'Updated Item']);
// Delete operations
DB::table('chronotrace_test')->delete();Tests different cache operations:
// Cache storage
Cache::put('chronotrace_test_key', 'test_value', 60);
// Cache retrieval
Cache::get('chronotrace_test_key');
// Cache invalidation
Cache::forget('chronotrace_test_key');
// Bulk operations
Cache::many(['key1' => 'value1', 'key2' => 'value2']);Tests custom event handling:
// Fire custom events
event(new ChronoTraceTestEvent(['data' => 'test']));
// Test event listeners
Event::listen('chronotrace.test', function ($data) {
// Event handling logic
});Use in automated testing:
# GitHub Actions example
- name: Test ChronoTrace Configuration
run: |
php artisan chronotrace:test-internal --with-db --with-cache --with-events
# Check exit code for success/failure
- name: Validate ChronoTrace
run: |
if php artisan chronotrace:test-internal --with-db; then
echo "β
ChronoTrace is properly configured"
else
echo "β ChronoTrace configuration issues detected"
exit 1
fiAfter running the test:
-
View the captured trace:
php artisan chronotrace:replay [trace-id]
-
Generate a test file from the captured operations:
php artisan chronotrace:replay [trace-id] --generate-test
-
Analyze the results to understand what ChronoTrace captured during internal operations
Cache operations failing: This is expected in minimal test environments. The database operations and events should still work correctly.
No operations captured: Check that ChronoTrace is enabled in your configuration and that the middleware is properly installed.
Permission errors: Ensure your application has proper database and file system permissions.
- Use
--verboseflag for more detailed output - Check your ChronoTrace configuration in
config/chronotrace.php - Verify that required listeners are registered in your EventServiceProvider
β Expected Results:
- Database operations should always be captured
- Events should be captured if properly configured
- Cache operations may fail in minimal environments
β Troubleshooting Failed Tests:
- Check database connection and permissions
- Verify event listeners are registered
- Ensure ChronoTrace is enabled in configuration
- chronotrace:record - Record HTTP requests
- chronotrace:replay - Replay captured traces
- chronotrace:list - List available traces
- chronotrace:diagnose - Diagnose configuration issues
- 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