pub struct ObservabilityState {
pub metrics_collector: Arc<MetricsCollector>,
pub log_collector: Arc<LogCollector>,
pub trace_collector: Arc<TraceCollector>,
pub system_metrics: Arc<SystemMetricsCollector>,
pub metrics_store: Arc<MetricsStore>,
pub log_store: Arc<LogStore>,
pub trace_store: Arc<TraceStore>,
pub alert_store: Arc<AlertStore>,
/* private fields */
}Expand description
Shared observability state for the runtime.
This struct encapsulates all observability components (collectors and stores) and provides a unified interface for recording and querying observability data.
Fields§
§metrics_collector: Arc<MetricsCollector>Metrics collector for buffering metrics.
log_collector: Arc<LogCollector>Log collector for buffering logs.
trace_collector: Arc<TraceCollector>Trace collector for buffering traces.
system_metrics: Arc<SystemMetricsCollector>System metrics collector.
metrics_store: Arc<MetricsStore>Metrics store for persistence.
log_store: Arc<LogStore>Log store for persistence.
trace_store: Arc<TraceStore>Trace store for persistence.
alert_store: Arc<AlertStore>Alert store for persistence.
Implementations§
Source§impl ObservabilityState
impl ObservabilityState
Sourcepub fn new(config: ObservabilityConfig, pool: PgPool) -> Self
pub fn new(config: ObservabilityConfig, pool: PgPool) -> Self
Create a new observability state from config and database pool.
Sourcepub fn is_enabled(&self) -> bool
pub fn is_enabled(&self) -> bool
Check if observability is enabled.
Sourcepub async fn record_metric(&self, metric: Metric)
pub async fn record_metric(&self, metric: Metric)
Record a metric.
Sourcepub async fn increment_counter(&self, name: impl Into<String>, value: f64)
pub async fn increment_counter(&self, name: impl Into<String>, value: f64)
Increment a counter metric.
Sourcepub async fn record_log(&self, log: LogEntry)
pub async fn record_log(&self, log: LogEntry)
Record a log entry.
Sourcepub async fn record_span(&self, span: Span)
pub async fn record_span(&self, span: Span)
Record a span.
Sourcepub fn start_background_tasks(&self) -> Vec<JoinHandle<()>>
pub fn start_background_tasks(&self) -> Vec<JoinHandle<()>>
Start background flush loops.
This spawns tasks that periodically flush collectors to stores and run cleanup based on retention policies.
Sourcepub fn tracing_layer(&self) -> ForgeTracingLayer
pub fn tracing_layer(&self) -> ForgeTracingLayer
Get a tracing layer that forwards logs to the LogCollector.
Use this to add log collection to your tracing subscriber:
use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::util::SubscriberInitExt;
tracing_subscriber::registry()
.with(observability.tracing_layer())
.with(tracing_subscriber::fmt::layer())
.init();Trait Implementations§
Source§impl Clone for ObservabilityState
impl Clone for ObservabilityState
Source§fn clone(&self) -> ObservabilityState
fn clone(&self) -> ObservabilityState
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for ObservabilityState
impl !RefUnwindSafe for ObservabilityState
impl Send for ObservabilityState
impl Sync for ObservabilityState
impl Unpin for ObservabilityState
impl !UnwindSafe for ObservabilityState
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more