Skip to content

traits

Core traits for the observability plugin system

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.

Core observability plugin trait

Required / Provided Methods

fn start_span(&self, name: &str, attributes: &[(&str, &str)]) -> SpanGuard

Start 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) -> bool

Check if the plugin is enabled

fn plugin_type(&self) -> &''static str

Get the plugin name/type

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

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) -> bool

Check if a level is enabled

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) -> Self

Set the plugin name

fn enabled(self, enabled: bool) -> Self

Enable/disable the plugin

Trait for plugins that support batching

Required / Provided Methods

fn batch_size(&self) -> usize

Get the current batch size

fn set_batch_size(&mut self, size: usize)

Set the batch size

fn flush_interval(&self) -> Duration

Get 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

Span guard that automatically ends spans when dropped

Methods

fn new(span_id: String, plugin: Arc<dyn ObservabilityPlugin>) -> Self
fn no_op() -> Self
fn span_id(&self) -> &str
fn duration(&self) -> Duration
fn add_attribute(&self, key: &str, value: &str)
fn set_status(&self, status: SpanStatus)

Log levels for structured logging

Variants

VariantDescription
Error
Warn
Info
Debug
Trace

Methods

fn as_str(&self) -> &''static str

Status of a span

Variants

VariantDescription
Ok
Error
Cancelled
fn create_labels(pairs: &[(&str, &str)]) -> HashMap<String, String>

Create a label map from key-value pairs

fn validate_metric_label_allowlist(label_keys: &[&str]) -> bool

Validate that label keys are within the allowlist.