Skip to main content

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
Use cases:
  • 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
Use cases:
  • Production deployments
  • High-throughput applications
  • Network-efficient export
  • When export latency is acceptable

BatchSpanProcessor

Basic usage

Configuration

Customize batch behavior with BatchConfig:

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:
This will:
  1. Stop accepting new spans
  2. Flush remaining spans in queue
  3. Wait for exports to complete
  4. 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:
Monitor your application for dropped spans. If the export rate can’t keep up with the span creation rate, increase max_queue_size or reduce span volume.

Export failures

Configure export timeout to handle slow exporters:

Best practices

Use batch processors in production - They provide the best balance of performance and reliability.
Configure based on load - Tune batch sizes and delays based on your application’s telemetry volume.
Always shut down gracefully - Call shutdown_tracer_provider() to ensure all telemetry is exported before exit.
Monitor export metrics - Watch for dropped spans, export errors, and queue depth to optimize configuration.

Common patterns

Development setup

Production setup

Testing setup

Span processors

Learn about span processor types

Log processors

Configure log processors