tracing crate for structured logging and instrumentation. This guide explains how to configure logging levels and span events.
Overview
BOOM’s logging system provides:- Structured logs: Events with context from active spans
- Configurable levels: Control verbosity via environment variables
- Span instrumentation: Track function execution and performance
- Error context: Automatic error source chain formatting
Log levels
Configure logging verbosity with theRUST_LOG environment variable.
Available levels
| Level | Usage | Example |
|---|---|---|
error | Actual errors | Database connection failed |
warn | Unexpected situations | Missing optional field |
info | Major lifecycle events | Worker started, Alert processed |
debug | Detailed diagnostics | Function entry/exit, Variable values |
trace | Very detailed diagnostics | Loop iterations, All function calls |
off | Disable logging | Silence all output |
Basic usage
Default directive
WhenRUST_LOG is not set, BOOM uses:
src/utils/o11y/logging.rs
info: Log INFO and above for all cratesort=error: Only log ERROR from theortcrate (ONNX Runtime)
The
ort crate is significantly noisier than other dependencies, so it’s limited to ERROR by default.Advanced filtering
TheRUST_LOG variable supports complex filtering directives.
Per-crate levels
Set different levels for different crates:debugfor BOOM codewarnfor MongoDB drivererrorfor Kafka client
Per-module levels
Target specific modules:Overriding defaults
Span events
Spans represent durations (like function execution) and provide context for log events.BOOM_SPAN_EVENTS variable
Enable span lifecycle events withBOOM_SPAN_EVENTS:
Available span events
| Event | Description | Use case |
|---|---|---|
new | Span created | Track when functions start |
enter | Span entered | Functions with multiple entry points |
exit | Span exited | Functions with multiple exit points |
close | Span closed (includes duration) | Performance profiling |
active | All events when span is active | Maximum verbosity |
full | All span events | Complete span lifecycle |
none | No span events (default) | Normal operation |
Profiling with span events
Theclose event includes execution time, useful for profiling:
Multiple span events
Combine multiple events with commas:Complete example
CombineRUST_LOG and BOOM_SPAN_EVENTS for detailed debugging:
- Sets DEBUG level for all crates
- Limits
ortto WARN - Shows span creation and completion with timing
Function instrumentation
BOOM uses the#[instrument] attribute to create spans automatically:
src/bin/scheduler.rs
Skipping fields
Theskip parameter excludes fields from span context:
self.
Custom fields
Add custom fields to spans:src/filter/base.rs
Error logging
BOOM provides macros for standardized error logging.log_error! macro
Log errors with automatic source chain formatting:as_error! macro
Create closures forResult methods:
Error source chains
BOOM automatically formats error source chains:src/utils/o11y/logging.rs
Log output format
BOOM’s log format includes:src/utils/o11y/logging.rs
Flame graphs
Generate flame graphs for performance profiling:Flame graphs use span instrumentation to track function execution time. Functions without
#[instrument] won’t appear in the graph.Logging conventions
BOOM follows these logging conventions:When to log at each level
INFO level
INFO level
Reserve INFO for major lifecycle events:
- Worker started/stopped
- Database connected
- Alert batch processed
- Filter executed
WARN level
WARN level
Use WARN for unexpected but non-critical issues:
- Missing optional configuration
- Retryable errors
- Deprecated features
- Performance degradation
ERROR level
ERROR level
Log actual errors that require attention:
- Database connection failures
- Invalid filter pipelines
- Unrecoverable processing errors
DEBUG level
DEBUG level
Use DEBUG for information useful during development:
- Function entry/exit
- Intermediate computation results
- Configuration values
- Cache hits/misses
TRACE level
TRACE level
Use TRACE for very detailed diagnostics:
- Loop iterations
- Individual field values
- Low-level protocol details
Error handling
FromCONTRIBUTING.md:
All other errors are recoverable errors and should be expressed using custom error types (usually enums) that implementKey principle: Don’t log errors if you’re propagating them withstd::error::Error. These errors should be propagated to the caller using the?operator. Each error is propagated until it’s handled, i.e., when a caller intercepts the error value to either use it for control flow or log it.
?. Only log where you handle the error.
Troubleshooting
No logs appearing
Check that you haven’t setRUST_LOG=off:
Too many logs from dependencies
Filter noisy crates:Span events not showing
VerifyBOOM_SPAN_EVENTS is set:
Next steps
Monitoring
Track pipeline performance with Prometheus metrics
Contributing
Learn BOOM’s development conventions
Tracing docs
Learn more about the tracing crate