Overview
Batch processors collect telemetry data in memory and export it in batches, reducing network overhead and improving performance. OpenTelemetry Rust provides batch processors for spans and logs.Batch processing is recommended for production deployments. Use simple processors only for development and debugging.
Processor types
Simple processors
Characteristics:- Export immediately on span/log end
- Synchronous or async depending on exporter
- No batching or buffering
- Suitable for development only
- Local development
- Debugging and testing
- Low-traffic applications
- When immediate export is required
Batch processors
Characteristics:- Buffer telemetry in memory
- Export in configurable batches
- Async export with runtime support
- Automatic retry and timeout handling
- Graceful shutdown support
- Production deployments
- High-throughput applications
- Network-efficient export
- When export latency is acceptable
BatchSpanProcessor
Basic usage
Configuration
Customize batch behavior withBatchConfig:
BatchConfig options
Environment variable configuration
BatchLogProcessor
Basic usage
Configuration
Environment variables
Runtime support
Batch processors require an async runtime:Tokio runtime
Tokio current-thread runtime
Shutdown and force flush
Graceful shutdown
Always shut down providers to ensure all telemetry is exported:- Stop accepting new spans
- Flush remaining spans in queue
- Wait for exports to complete
- Clean up resources
Force flush
Manually trigger export before timeout:Performance tuning
High throughput
For applications generating many spans:Low latency
For applications requiring faster export:Memory constrained
For environments with limited memory:Multiple processors
Combine batch and simple processors for different use cases:Monitoring batch processors
Queue overflow
When the queue is full, new spans are dropped:Export failures
Configure export timeout to handle slow exporters:Best practices
Configure based on load - Tune batch sizes and delays based on your application’s telemetry volume.
Monitor export metrics - Watch for dropped spans, export errors, and queue depth to optimize configuration.
Common patterns
Development setup
Production setup
Testing setup
Related
Span processors
Learn about span processor types
Log processors
Configure log processors