pub struct BatchSpanProcessor { /* private fields */ }
Expand description
The BatchSpanProcessor
collects finished spans in a buffer and exports them
in batches to the configured SpanExporter
. This processor is ideal for
high-throughput environments, as it minimizes the overhead of exporting spans
individually. It uses a dedicated background thread to manage and export spans
asynchronously, ensuring that the application’s main execution flow is not blocked.
This processor supports the following configurations:
- Queue size: Maximum number of spans that can be buffered.
- Batch size: Maximum number of spans to include in a single export.
- Scheduled delay: Frequency at which the batch is exported.
When using this processor with the OTLP Exporter, the following exporter features are supported:
grpc-tonic
: RequiresTracerProvider
to be created within a tokio runtime.reqwest-blocking-client
: Works with a regularmain
ortokio::main
.
In other words, other clients like reqwest
and hyper
are not supported.
BatchSpanProcessor
buffers spans in memory and exports them in batches. An
export is triggered when max_export_batch_size
is reached or every
scheduled_delay
milliseconds. Users can explicitly trigger an export using
the force_flush
method. Shutdown also triggers an export of all buffered
spans and is recommended to be called before the application exits to ensure
all buffered spans are exported.
Warning: When using tokio’s current-thread runtime, shutdown()
, which
is a blocking call ,should not be called from your main thread. This can
cause deadlock. Instead, call shutdown()
from a separate thread or use
tokio’s spawn_blocking
.
Implementations§
Source§impl BatchSpanProcessor
impl BatchSpanProcessor
Sourcepub fn new<E>(exporter: E, config: BatchConfig) -> Selfwhere
E: SpanExporter + Send + 'static,
pub fn new<E>(exporter: E, config: BatchConfig) -> Selfwhere
E: SpanExporter + Send + 'static,
Creates a new instance of BatchSpanProcessor
.
Sourcepub fn builder<E>(exporter: E) -> BatchSpanProcessorBuilder<E>where
E: SpanExporter + Send + 'static,
pub fn builder<E>(exporter: E) -> BatchSpanProcessorBuilder<E>where
E: SpanExporter + Send + 'static,
builder
Trait Implementations§
Source§impl Debug for BatchSpanProcessor
impl Debug for BatchSpanProcessor
Source§impl SpanProcessor for BatchSpanProcessor
impl SpanProcessor for BatchSpanProcessor
Source§fn force_flush(&self) -> OTelSdkResult
fn force_flush(&self) -> OTelSdkResult
Flushes all pending spans.
Source§fn shutdown(&self) -> OTelSdkResult
fn shutdown(&self) -> OTelSdkResult
Shuts down the processor.
Source§fn set_resource(&mut self, resource: &Resource)
fn set_resource(&mut self, resource: &Resource)
Set the resource for the processor.