traits
Core traits for the observability plugin system
Constants
Section titled “Constants”METRIC_LABEL_ALLOWLIST
Section titled “METRIC_LABEL_ALLOWLIST”const METRIC_LABEL_ALLOWLIST: &[&str] = ;Metric label allowlist for cardinality reduction.
Backends should treat unknown labels as optional or drop them to avoid cardinality explosions.
Traits
Section titled “Traits”ObservabilityPlugin
Section titled “ObservabilityPlugin”Core observability plugin trait
Required / Provided Methods
fn start_span(&self, name: &str, attributes: &[(&str, &str)]) -> SpanGuardStart a new span and return a guard
fn end_span(&self, span_id: &str)End a span by ID
fn add_span_attribute(&self, span_id: &str, key: &str, value: &str)Add an attribute to an existing span
fn set_span_status(&self, span_id: &str, status: SpanStatus)Set the status of a span
fn record_metric(&self, name: &str, value: f64, labels: &[(&str, &str)])Record a metric with labels
fn increment_counter(&self, name: &str, labels: &[(&str, &str)])Increment a counter metric
fn record_histogram(&self, name: &str, value: f64, labels: &[(&str, &str)])Record a histogram value
fn log_structured(&self, level: LogLevel, message: &str, fields: &JsonValue)Log a structured message with fields
fn log(&self, level: LogLevel, message: &str)Log a simple message
fn write_log(&self, message: &str)Write log output (implementation-specific)
fn flush(&self) -> ObservabilityResult<()>Flush any pending telemetry data
fn is_enabled(&self) -> boolCheck if the plugin is enabled
fn plugin_type(&self) -> &''static strGet the plugin name/type
MetricsCollector
Section titled “MetricsCollector”Trait for collecting and managing metrics
Required / Provided Methods
fn register_counter(&mut self, name: &str, description: &str, labels: &[&str]) -> ObservabilityResult<()>Register a new counter
fn register_histogram(&mut self, name: &str, description: &str, buckets: &[f64], labels: &[&str]) -> ObservabilityResult<()>Register a new histogram
fn register_gauge(&mut self, name: &str, description: &str, labels: &[&str]) -> ObservabilityResult<()>Register a new gauge
fn record_counter(&self, name: &str, value: f64, labels: &HashMap<String, String>) -> ObservabilityResult<()>Record a counter increment
fn record_histogram(&self, name: &str, value: f64, labels: &HashMap<String, String>) -> ObservabilityResult<()>Record a histogram observation
fn set_gauge(&self, name: &str, value: f64, labels: &HashMap<String, String>) -> ObservabilityResult<()>Set a gauge value
fn get_metrics(&self) -> HashMap<String, f64>Get current metric values (for testing/debugging)
fn clear(&mut self)Clear all metrics
StructuredLogger
Section titled “StructuredLogger”Trait for structured logging
Required / Provided Methods
fn log_with_trace(&self, level: LogLevel, message: &str, fields: &JsonValue, trace_id: Option<&str>, span_id: Option<&str>)Log with trace context correlation
fn log_performance(&self, operation: &str, duration: Duration, success: bool, additional_fields: &JsonValue)Log performance metrics
fn log_error(&self, error: &dyn Error, context: &JsonValue)Log errors with context
fn set_level(&mut self, level: LogLevel)Set the minimum log level
fn is_level_enabled(&self, level: LogLevel) -> boolCheck if a level is enabled
ObservabilityBuilder
Section titled “ObservabilityBuilder”Builder trait for creating observability plugins
Associated Types
type Plugin—
Required / Provided Methods
fn build(self) -> ObservabilityResult<<Self as ?>::Plugin>Build the plugin with the current configuration
fn with_name<impl Into<String>>(self, name: impl Into) -> SelfSet the plugin name
fn enabled(self, enabled: bool) -> SelfEnable/disable the plugin
BatchingSupport
Section titled “BatchingSupport”Trait for plugins that support batching
Required / Provided Methods
fn batch_size(&self) -> usizeGet the current batch size
fn set_batch_size(&mut self, size: usize)Set the batch size
fn flush_interval(&self) -> DurationGet the flush interval
fn set_flush_interval(&mut self, interval: Duration)Set the flush interval
fn force_flush(&self) -> ObservabilityResult<()>Force flush all batched data
Structs
Section titled “Structs”SpanGuard
Section titled “SpanGuard”Span guard that automatically ends spans when dropped
Methods
fn new(span_id: String, plugin: Arc<dyn ObservabilityPlugin>) -> Selffn no_op() -> Selfspan_id
Section titled “span_id”fn span_id(&self) -> &strduration
Section titled “duration”fn duration(&self) -> Durationadd_attribute
Section titled “add_attribute”fn add_attribute(&self, key: &str, value: &str)set_status
Section titled “set_status”fn set_status(&self, status: SpanStatus)LogLevel
Section titled “LogLevel”Log levels for structured logging
Variants
| Variant | Description |
|---|---|
Error | |
Warn | |
Info | |
Debug | |
Trace |
Methods
as_str
Section titled “as_str”fn as_str(&self) -> &''static strSpanStatus
Section titled “SpanStatus”Status of a span
Variants
| Variant | Description |
|---|---|
Ok | |
Error | |
Cancelled |
Functions
Section titled “Functions”create_labels
Section titled “create_labels”fn create_labels(pairs: &[(&str, &str)]) -> HashMap<String, String>Create a label map from key-value pairs
validate_metric_label_allowlist
Section titled “validate_metric_label_allowlist”fn validate_metric_label_allowlist(label_keys: &[&str]) -> boolValidate that label keys are within the allowlist.