batching
Smart batching system for telemetry data to optimize performance
Traits
Section titled “Traits”MemoryEstimator
Section titled “MemoryEstimator”Trait for estimating memory usage
Required / Provided Methods
fn estimated_size(&self) -> usizeStructs
Section titled “Structs”BatchingConfig
Section titled “BatchingConfig”Configuration for batching behavior
Fields
| Field | Type | Description |
|---|---|---|
max_batch_size | usize | Maximum number of items in a batch |
flush_interval | web_time::Duration | Maximum time to wait before flushing a batch |
max_memory_bytes | usize | Maximum memory usage in bytes (approximate) |
drop_on_overflow | bool | Whether to drop items when buffer is full |
min_batch_size | usize | Minimum batch size to trigger early flush |
SpanData
Section titled “SpanData”Span data for batching
Fields
| Field | Type | Description |
|---|---|---|
span_id | String | |
trace_id | String | |
parent_span_id | Option<String> | |
name | String | |
start_time | web_time::Instant | |
end_time | Option<web_time::Instant> | |
status | SpanStatus | |
attributes | HashMap<String, String> |
Methods
fn new(span_id: String, trace_id: String, name: String) -> Selfwith_parent
Section titled “with_parent”fn with_parent(self, parent_span_id: String) -> Selfadd_attribute
Section titled “add_attribute”fn add_attribute(&mut self, key: String, value: String)fn end(&mut self)duration
Section titled “duration”fn duration(&self) -> Option<Duration>MetricData
Section titled “MetricData”Metric data for batching
Fields
| Field | Type | Description |
|---|---|---|
name | String | |
value | f64 | |
labels | HashMap<String, String> | |
timestamp | web_time::Instant | |
metric_type | MetricType |
Methods
fn new(name: String, value: f64, labels: HashMap<String, String>, metric_type: MetricType) -> SelfLogData
Section titled “LogData”Log data for batching
Fields
| Field | Type | Description |
|---|---|---|
level | LogLevel | |
message | String | |
fields | serde_json::Value | |
timestamp | web_time::Instant | |
trace_id | Option<String> | |
span_id | Option<String> |
Methods
fn new(level: LogLevel, message: String, fields: JsonValue) -> Selfwith_trace_context
Section titled “with_trace_context”fn with_trace_context(self, trace_id: String, span_id: String) -> SelfMemoryEfficientBuffer
Section titled “MemoryEfficientBuffer”Memory-efficient buffer with overflow handling
Methods
fn new(max_size: usize, max_memory: usize, drop_on_overflow: bool) -> Selffn push(&mut self, item: T) -> boolwhere T: MemoryEstimatorfn drain(&mut self) -> Vec<T>fn len(&self) -> usizeis_empty
Section titled “is_empty”fn is_empty(&self) -> booldropped_count
Section titled “dropped_count”fn dropped_count(&self) -> u64memory_usage
Section titled “memory_usage”fn memory_usage(&self) -> usizeBatchingManager
Section titled “BatchingManager”Batching manager for telemetry data
Methods
fn new(config: BatchingConfig) -> Selfset_flush_callback
Section titled “set_flush_callback”fn set_flush_callback<F>(&mut self, callback: F)where F: Fn + Send + Sync + ?Set the flush callback function
add_span
Section titled “add_span”fn add_span(&self, span: SpanData) -> ObservabilityResult<()>Add a span to the batch
add_metric
Section titled “add_metric”fn add_metric(&self, metric: MetricData) -> ObservabilityResult<()>Add a metric to the batch
add_log
Section titled “add_log”fn add_log(&self, log: LogData) -> ObservabilityResult<()>Add a log to the batch
flush_all
Section titled “flush_all”fn flush_all(&self) -> ObservabilityResult<()>Force flush all buffers
get_stats
Section titled “get_stats”fn get_stats(&self) -> BatchingStatsGet buffer statistics
BatchingStats
Section titled “BatchingStats”Statistics about batching buffers
Fields
| Field | Type | Description |
|---|---|---|
span_count | usize | |
metric_count | usize | |
log_count | usize | |
span_dropped | u64 | |
metric_dropped | u64 | |
log_dropped | u64 | |
memory_usage | usize | |
last_flush | web_time::Instant |
Methods
total_items
Section titled “total_items”fn total_items(&self) -> usizetotal_dropped
Section titled “total_dropped”fn total_dropped(&self) -> u64TelemetryData
Section titled “TelemetryData”Telemetry data types for batching
Variants
| Variant | Description |
|---|---|
Span(SpanData) | |
Metric(MetricData) | |
Log(LogData) |
Methods
estimated_size
Section titled “estimated_size”fn estimated_size(&self) -> usizeEstimate memory usage of this telemetry data
MetricType
Section titled “MetricType”Variants
| Variant | Description |
|---|---|
Counter | |
Histogram | |
Gauge |