Skip to content

batching

Smart batching system for telemetry data to optimize performance

Trait for estimating memory usage

Required / Provided Methods

fn estimated_size(&self) -> usize

Configuration for batching behavior

Fields

FieldTypeDescription
max_batch_sizeusizeMaximum number of items in a batch
flush_intervalweb_time::DurationMaximum time to wait before flushing a batch
max_memory_bytesusizeMaximum memory usage in bytes (approximate)
drop_on_overflowboolWhether to drop items when buffer is full
min_batch_sizeusizeMinimum batch size to trigger early flush

Span data for batching

Fields

FieldTypeDescription
span_idString
trace_idString
parent_span_idOption<String>
nameString
start_timeweb_time::Instant
end_timeOption<web_time::Instant>
statusSpanStatus
attributesHashMap<String, String>

Methods

fn new(span_id: String, trace_id: String, name: String) -> Self
fn with_parent(self, parent_span_id: String) -> Self
fn add_attribute(&mut self, key: String, value: String)
fn end(&mut self)
fn duration(&self) -> Option<Duration>

Metric data for batching

Fields

FieldTypeDescription
nameString
valuef64
labelsHashMap&lt;String, String&gt;
timestampweb_time::Instant
metric_typeMetricType

Methods

fn new(name: String, value: f64, labels: HashMap<String, String>, metric_type: MetricType) -> Self

Log data for batching

Fields

FieldTypeDescription
levelLogLevel
messageString
fieldsserde_json::Value
timestampweb_time::Instant
trace_idOption&lt;String&gt;
span_idOption&lt;String&gt;

Methods

fn new(level: LogLevel, message: String, fields: JsonValue) -> Self
fn with_trace_context(self, trace_id: String, span_id: String) -> Self

Memory-efficient buffer with overflow handling

Methods

fn new(max_size: usize, max_memory: usize, drop_on_overflow: bool) -> Self
fn push(&mut self, item: T) -> bool
where
T: MemoryEstimator
fn drain(&mut self) -> Vec<T>
fn len(&self) -> usize
fn is_empty(&self) -> bool
fn dropped_count(&self) -> u64
fn memory_usage(&self) -> usize

Batching manager for telemetry data

Methods

fn new(config: BatchingConfig) -> Self
fn set_flush_callback<F>(&mut self, callback: F)
where
F: Fn + Send + Sync + ?

Set the flush callback function

fn add_span(&self, span: SpanData) -> ObservabilityResult<()>

Add a span to the batch

fn add_metric(&self, metric: MetricData) -> ObservabilityResult<()>

Add a metric to the batch

fn add_log(&self, log: LogData) -> ObservabilityResult<()>

Add a log to the batch

fn flush_all(&self) -> ObservabilityResult<()>

Force flush all buffers

fn get_stats(&self) -> BatchingStats

Get buffer statistics

Statistics about batching buffers

Fields

FieldTypeDescription
span_countusize
metric_countusize
log_countusize
span_droppedu64
metric_droppedu64
log_droppedu64
memory_usageusize
last_flushweb_time::Instant

Methods

fn total_items(&self) -> usize
fn total_dropped(&self) -> u64

Telemetry data types for batching

Variants

VariantDescription
Span(SpanData)
Metric(MetricData)
Log(LogData)

Methods

fn estimated_size(&self) -> usize

Estimate memory usage of this telemetry data

Variants

VariantDescription
Counter
Histogram
Gauge