Documentation Index
Fetch the complete documentation index at: https://mintlify.com/open-telemetry/opentelemetry-rust/llms.txt
Use this file to discover all available pages before exploring further.
Overview
Log processors are responsible for receiving log records from loggers and forwarding them to exporters. OpenTelemetry SDK provides two built-in processors:- SimpleLogProcessor: Exports logs immediately (for development/debugging)
- BatchLogProcessor: Buffers logs and exports in batches (for production)
LogProcessor Trait
All processors implement theLogProcessor trait:
SimpleLogProcessor
TheSimpleLogProcessor exports log records immediately when they are emitted. It’s synchronous and suitable for debugging and testing, but not recommended for production due to performance overhead.
Characteristics
- Synchronous export on each log emission
- No batching or buffering
- Immediate visibility of logs
- Higher overhead per log record
- Simpler error handling
Usage
When to Use
Development & Debugging
Development & Debugging
Use
SimpleLogProcessor when:- Developing and debugging locally
- Running tests that need immediate log visibility
- Prototyping with small log volumes
- Using simple exporters like stdout
NOT for Production
NOT for Production
Avoid in production because:
- Each log blocks the emitting thread
- High overhead for high-throughput scenarios
- Network latency affects application performance
- No batching efficiency
Runtime Compatibility
When usingSimpleLogProcessor with different OTLP exporter clients:
| Exporter Feature | Runtime Required | Emit From |
|---|---|---|
grpc-tonic | Tokio runtime | Any thread |
reqwest-blocking-client | No runtime needed | Non-tokio threads only |
reqwest-client | Tokio runtime | Tokio runtime threads |
BatchLogProcessor
TheBatchLogProcessor buffers log records in memory and exports them in batches using a background thread. This is the recommended processor for production environments.
Characteristics
- Asynchronous export via background thread
- Configurable batching and scheduling
- Reduced export overhead
- Bounded memory usage
- Optimal for high-throughput scenarios
Basic Usage
Configuration
Configure batch behavior usingBatchConfigBuilder:
Configuration Parameters
| Parameter | Default | Environment Variable | Description |
|---|---|---|---|
max_queue_size | 2048 | OTEL_BLRP_MAX_QUEUE_SIZE | Maximum number of logs buffered in queue |
max_export_batch_size | 512 | OTEL_BLRP_MAX_EXPORT_BATCH_SIZE | Maximum logs in a single export batch |
scheduled_delay | 1s | OTEL_BLRP_SCHEDULE_DELAY | Delay between consecutive exports |
max_export_batch_size must be less than or equal to max_queue_size.Export Triggers
Logs are exported when:- Batch size reached: When
max_export_batch_sizelogs are buffered - Scheduled delay: Every
scheduled_delaymilliseconds - Force flush: When
force_flush()is called - Shutdown: When
shutdown()is called
Example: Production Configuration
Runtime Compatibility
When usingBatchLogProcessor with OTLP exporters:
| Exporter Feature | Runtime Required | Notes |
|---|---|---|
grpc-tonic | Tokio runtime | LoggerProvider created in tokio runtime |
reqwest-blocking-client | No runtime needed | Works with regular main or tokio::main |
reqwest-client | Not supported | Use grpc-tonic or reqwest-blocking-client |
hyper | Not supported | Use grpc-tonic or reqwest-blocking-client |
Force Flush
Explicitly export buffered logs:- Checkpointing application state
- Deploying new versions
- Handling critical errors
Shutdown
Always shutdown before application exit:Dropped Logs
If the queue is full, logs are dropped and counted. The count is logged at shutdown:Custom Log Processors
You can implement custom processors for specialized behavior:event_enabled Optimization
Theevent_enabled() method allows early filtering to skip expensive logging operations:
Processor Comparison
| Feature | SimpleLogProcessor | BatchLogProcessor |
|---|---|---|
| Export Mode | Synchronous | Asynchronous (background) |
| Buffering | None | Yes |
| Overhead | High (per log) | Low (amortized) |
| Latency | None | Configurable |
| Memory Usage | Minimal | Bounded by queue size |
| Production Ready | No | Yes |
| Best For | Development, debugging | Production |
| Dropped Logs | Never | If queue full |
| Background Thread | No | Yes |
Best Practices
Use BatchLogProcessor in Production
Use BatchLogProcessor in Production
Always use
BatchLogProcessor for production deployments:- Lower overhead
- Better performance under load
- Configurable batching behavior
Configure Based on Load
Configure Based on Load
Adjust batch configuration based on your log volume:
Always Shutdown Cleanly
Always Shutdown Cleanly
Call
shutdown() before application exit to flush remaining logs:Monitor Dropped Logs
Monitor Dropped Logs
Check for dropped log messages in production and adjust
max_queue_size if needed.Use event_enabled for Performance
Use event_enabled for Performance
Implement
event_enabled() in custom processors to skip expensive operations for filtered logs.Troubleshooting
Logs not exported
-
Forgot to shutdown: Always call
provider.shutdown() -
Batch not full: Wait for
scheduled_delayor callforce_flush() -
Queue full: Increase
max_queue_sizeor export more frequently
High latency
If usingSimpleLogProcessor in production, switch to BatchLogProcessor:
Memory usage too high
Reducemax_queue_size or increase export frequency:
Logs dropped
Increase queue size or export more frequently:See Also
log Appender
Bridge logs from the
log cratetracing Appender
Bridge logs from the
tracing crateBridge API
Understanding the core API
Overview
Return to logs overview