Debugging Guide¶
Step-by-step procedures for debugging Expensis automation issues.
Debugging Strategy¶
graph TD
A[Issue Reported] --> B{Known Issue?}
B -->|Yes| C[Check Common Issues]
B -->|No| D[Identify Component]
D --> E{Component Type?}
E -->|Sync| F[Debug Sync Issues]
E -->|Totals| G[Debug Calculation Issues]
E -->|Chain| H[Debug Chain Issues]
E -->|Other| I[General Debugging]
C --> J[Apply Solution]
F --> J
G --> J
H --> J
I --> J
style A fill:#e3f2fd
style J fill:#e8f5e9
Step 1: Identify the Problem¶
Questions to Ask¶
- What's not working?
- Specific sync failing?
- All syncs failing?
- Totals not calculating?
-
Chain not executing?
-
When did it start?
- After deployment?
- After configuration change?
- Suddenly?
-
Gradually?
-
Is it consistent?
- Always fails?
- Intermittent?
- Specific customers only?
- Specific providers only?
Debugging Sync Issues¶
Sync Not Running at All¶
Check 1: Is cron running?
Check 2: Recent sync tasks
Check 3: Manual execution
Specific Provider Sync Failing¶
Check 1: Sync task status
SELECT
st.id,
sp.sync_type,
st.status,
st.error_message,
st.created_at,
st.updated_at
FROM sync_task st
JOIN sync_profile sp ON st.sync_profile_id = sp.id
WHERE st.customer_id = 123
ORDER BY st.created_at DESC
LIMIT 10;
Check 2: Sync profile active
Check 3: Run manually with verbose output
# For KPN SP16
php bin/console kpn:sp16:sync --customer=123 -vvv
# For Vodafone
php bin/console vodafone:sync --customer=123 -vvv
# Generic sync
php bin/console sync:manager --customer=123 --force -vvv
Check 4: Check handler logs
Debugging Totals Calculation¶
Totals Are Zero¶
Check 1: Do CDRs exist?
SELECT COUNT(*) as cdr_count
FROM call_detail_record
WHERE customer_id = 123
AND call_date >= '2025-01-01'
AND call_date < '2025-02-01';
Check 2: Are CDRs linked to devices?
SELECT
COUNT(*) as total_cdrs,
SUM(CASE WHEN device_id IS NULL THEN 1 ELSE 0 END) as unlinked_cdrs
FROM call_detail_record
WHERE customer_id = 123
AND call_date >= '2025-01-01';
Check 3: Do devices have subscriptions?
SELECT
d.id,
d.code,
d.subscription_id,
s.rate_plan_id
FROM device d
LEFT JOIN subscription s ON d.subscription_id = s.id
WHERE d.customer_id = 123
AND d.subscription_id IS NULL;
Check 4: Run calculation manually
Totals Wrong (Not Matching Provider)¶
Check 1: Compare CDR count
SELECT
call_type,
COUNT(*) as count,
SUM(duration) as total_duration,
SUM(cost) as total_cost
FROM call_detail_record
WHERE customer_id = 123
AND call_date >= '2025-01-01'
AND call_date < '2025-02-01'
GROUP BY call_type;
Check 2: Verify rate plans
SELECT
s.id,
s.name,
s.rate_plan_id,
rp.name as rate_plan_name
FROM subscription s
LEFT JOIN rate_plan rp ON s.rate_plan_id = rp.id
WHERE s.customer_id = 123;
Check 3: Check totals breakdown
Debugging Command Chains¶
Chain Not Executing¶
Check 1: Is MessageConsumedHandler present?
Check 2: Is it registered?
Check 3: Test simple chain
# Run totals calculation (has chain to backup)
php bin/console totals:new --customer=123 --cycle=2025-01-01
# Check if backup created
SELECT * FROM total_usage_new_backup_table
WHERE customer_id = 123
AND cycle_start_date = '2025-01-01';
Check 4: Check event logs
General Debugging Tools¶
View Recent Errors¶
Check Messenger Status¶
View Event Subscribers¶
Check Services¶
Test Database Connection¶
Advanced Debugging¶
Enable Debug Mode¶
Warning: Only use in development/staging!
Xdebug Breakpoints¶
// In handler
public function __invoke(ExampleCommand $command)
{
xdebug_break(); // Breakpoint here
// Your code
}
Profiling Slow Operations¶
$start = microtime(true);
// Your code here
$duration = microtime(true) - $start;
$this->logger->info("Operation took {$duration} seconds");
Memory Debugging¶
Related Documentation¶
- Common Issues - Known problems and solutions
- FAQ - Frequently asked questions
- Workflows - Understand execution flow
- Single Points of Failure - Critical components