- SimpleSpanProcessor exports each span synchronously when it ends — convenient for local debugging but adds latency and should not be used in production.
- BatchSpanProcessor buffers spans and exports them from a background worker thread in batches — recommended for production to minimize impact on application latency.
| Processor | Behavior | Use case |
|---|---|---|
| SimpleSpanProcessor | Exports each span synchronously when it ends | Local development, debugging |
| BatchSpanProcessor | Buffers spans and exports in background batches | Production (low-latency deployments) |
Example: SimpleSpanProcessor (local testing)
Keep this minimal configuration for local debugging. It uses the ConsoleSpanExporter and SimpleSpanProcessor. Do not use this in production because exporting occurs on the same thread as your application code.- SimpleSpanProcessor synchronously invokes the exporter when each span ends, which can block the application thread and increase latency.
Use SimpleSpanProcessor only for local development or interactive debugging. For production deployments, prefer BatchSpanProcessor to avoid adding latency to your application’s main threads.
Switching to BatchSpanProcessor (production)
BatchSpanProcessor aggregates spans and exports them on a schedule from a separate worker thread. To switch, replace SimpleSpanProcessor with BatchSpanProcessor and pass the exporter instance to its constructor.If you call Always pass the exporter instance (for example,
BatchSpanProcessor() without passing an exporter you will see:ConsoleSpanExporter() or an OTLP exporter).- BatchSpanProcessor reduces application-thread latency by exporting spans on a worker thread in batches.
- Because batching is asynchronous, console output or exported spans may appear slightly delayed compared to SimpleSpanProcessor.
- Always call
trace.get_tracer_provider().shutdown()(or otherwise shut down the provider) at process termination to flush any remaining spans. - For production, prefer an exporter suited to your backend (for example, OTLP exporter). See the References section below for exporter options and configuration details.
Sample console output (ConsoleSpanExporter)
Below is a representative example of a span exported by ConsoleSpanExporter (formatted JSON):- Use SimpleSpanProcessor for quick local debugging only.
- Use BatchSpanProcessor in production to reduce the latency impact on your main application threads.
- Always provide an exporter instance to BatchSpanProcessor and ensure the tracer provider is shut down at application exit to flush spans.
Links and References
- OpenTelemetry Python Instrumentation
- OpenTelemetry Python Exporters — Console and OTLP
- OTLP exporter configuration
- OpenTelemetry Tracing SDK for Python