WASM Procedures: Monitoring & Debugging
WASM Procedures: Monitoring & Debugging
Documentation Home > User Guides > Features > Monitoring & Debugging
Overview
This guide covers comprehensive monitoring, debugging, logging, and profiling capabilities for WASM procedures in HeliosDB, enabling effective production operation and troubleshooting.
Related Sections:
- Performance - Performance optimization
- Procedure Management - Managing procedures
- Security Model - Security monitoring
Monitoring & Debugging
Execution Metrics
View Procedure Statistics
SELECT procedure_name, total_calls, successful_calls, failed_calls, success_rate, avg_execution_time_ms, min_execution_time_ms, max_execution_time_ms, p50_execution_time_ms, p95_execution_time_ms, p99_execution_time_msFROM heliosdb_procedure_metricsWHERE procedure_name = 'calculate_discount';Example Output:
procedure_name | total_calls | successful_calls | failed_calls | success_rate | avg_execution_time_ms--------------------|-------------|------------------|--------------|--------------|----------------------calculate_discount | 15234 | 15198 | 36 | 99.76% | 7.3Real-Time Monitoring
-- Monitor active executionsSELECT procedure_name, execution_id, started_at, duration_ms, status, user_idFROM heliosdb_procedure_executionsWHERE status = 'running'ORDER BY duration_ms DESC;Fuel Consumption
SELECT procedure_name, avg_fuel_consumed, max_fuel_consumed, fuel_limit, fuel_exceeded_countFROM heliosdb_procedure_fuel_stats;Example Output:
procedure_name | avg_fuel_consumed | max_fuel_consumed | fuel_limit | fuel_exceeded_count--------------------|-------------------|-------------------|--------------|--------------------calculate_discount | 145,234 | 289,421 | 1,000,000 | 0process_order | 1,234,567 | 2,456,789 | 10,000,000 | 3Memory Usage
SELECT procedure_name, avg_memory_bytes, max_memory_bytes, memory_limit_bytes, oom_countFROM heliosdb_procedure_memory_stats;Error Tracking
-- View recent errorsSELECT procedure_name, error_message, error_count, last_occurrence, stack_traceFROM heliosdb_procedure_errorsWHERE last_occurrence > NOW() - INTERVAL '1 hour'ORDER BY error_count DESC;Example Output:
procedure_name | error_message | error_count | last_occurrence-----------------|----------------------------|-------------|-------------------process_order | Insufficient funds | 12 | 2025-11-02 14:32:15transfer_funds | Account not found | 5 | 2025-11-02 14:28:42Logging
Configure Log Level
-- Set global log levelSET heliosdb.procedure_log_level = 'info'; -- trace, debug, info, warn, error
-- Set per-procedure log levelALTER PROCEDURE my_procedureSET log_level = 'debug';View Procedure Logs
SELECT timestamp, procedure_name, log_level, message, execution_idFROM heliosdb_procedure_logsWHERE procedure_name = 'calculate_discount' AND timestamp > NOW() - INTERVAL '10 minutes'ORDER BY timestamp DESCLIMIT 100;Log Retention
-- Set log retention period (days)SET heliosdb.procedure_log_retention_days = 30;
-- Manual cleanupDELETE FROM heliosdb_procedure_logsWHERE timestamp < NOW() - INTERVAL '30 days';Profiling
Enable detailed profiling for performance analysis:
-- Enable profilingALTER PROCEDURE my_procedureSET profiling = true;
-- Run procedureSELECT my_procedure(params);
-- View profiling resultsSELECT * FROM heliosdb_procedure_profileWHERE procedure_name = 'my_procedure'ORDER BY timestamp DESCLIMIT 1;Profiling Output:
{ "procedure_name": "my_procedure", "total_time_ms": 23.4, "compilation_time_ms": 2.1, "execution_time_ms": 21.3, "breakdown": { "database_calls": { "count": 5, "total_time_ms": 15.2 }, "host_functions": { "count": 12, "total_time_ms": 3.1 }, "computation": { "time_ms": 3.0 } }, "memory": { "peak_bytes": 2048576, "allocated_bytes": 1843200, "freed_bytes": 1024000 }}Debugging
Enable Debug Mode
ALTER PROCEDURE my_procedureSET debug_mode = true;In debug mode:
- Detailed logging enabled
- Stack traces included in errors
- WASM source maps loaded (if available)
- Slower execution (not for production)
Stack Traces
When errors occur, get detailed stack traces:
SELECT procedure_name, error_message, stack_trace, source_locationFROM heliosdb_procedure_errorsWHERE procedure_name = 'my_procedure'ORDER BY occurred_at DESCLIMIT 1;Example:
error_message: Division by zerostack_trace: at calculate_total (procedure.wasm:calculate_total:145) at process_order (procedure.wasm:process_order:67) at main (procedure.wasm:main:12)source_location: src/lib.rs:145:9Alerts
Configure alerts for anomalies:
-- Create alert ruleCREATE ALERT RULE slow_procedure_alertON heliosdb_procedure_metricsWHEN avg_execution_time_ms > 1000THEN NOTIFY 'ops-team@example.com';
-- Create error rate alertCREATE ALERT RULE high_error_rateON heliosdb_procedure_metricsWHEN success_rate < 95.0THEN NOTIFY 'ops-team@example.com';Logging Best Practices
- Use appropriate log levels:
log_trace("Entering function calculate_discount"); // Development onlylog_debug(&format!("Processing order {}", order_id)); // Debugginglog_info("Order processed successfully"); // Normal operationslog_warn("Slow query detected"); // Potential issueslog_error("Failed to process order"); // Errors- Include context:
log_info(&format!( "User {} performed action {} on resource {} at {}", user_id, action, resource, timestamp));- Avoid logging sensitive data:
// Badlog_info(&format!("Password: {}", password));
// Goodlog_info("User authentication attempted");- Use structured logging:
log_json(LogLevel::Info, json!({ "event": "order_processed", "order_id": order_id, "user_id": user_id, "total": total, "processing_time_ms": elapsed}));Key Takeaways
- Comprehensive Metrics: Track execution time, success rate, fuel consumption, and memory usage
- Real-Time Monitoring: Monitor active executions and identify slow procedures
- Error Tracking: Aggregate and track errors with detailed stack traces
- Flexible Logging: Configure log levels globally or per-procedure
- Profiling: Deep performance analysis with breakdown by operation type
- Alerts: Proactive notification of performance degradation or errors
Monitoring Checklist
- Monitor success rate to detect failing procedures
- Track p95/p99 execution times to identify performance regressions
- Review fuel consumption to prevent resource exhaustion
- Check memory usage to avoid OOM errors
- Configure alerts for critical thresholds
- Retain logs for compliance and debugging
Next Steps
- Advanced Topics - Advanced monitoring patterns
- Performance - Optimize based on metrics
- API Reference - Complete API documentation
Navigation: ← Performance | Index | Advanced Topics →