obzenflow_core 0.2.1

Core domain layer for ObzenFlow - pure abstractions with minimal dependencies
Documentation
// SPDX-License-Identifier: MIT OR Apache-2.0
// SPDX-FileCopyrightText: 2025-2026 ObzenFlow Contributors
// https://obzenflow.dev

//! Observability context that can be attached to any event (wide events pattern)

use super::CompositeActivationContext;
use serde::{Deserialize, Serialize};
use serde_json::Value;

/// Observability context that can be attached to any event
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[non_exhaustive]
pub struct ObservabilityContext {
    /// Composite input facts that causally contribute to this event.
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
    pub composite_activations: Vec<CompositeActivationContext>,

    /// Metrics snapshots at event time
    #[serde(skip_serializing_if = "Option::is_none")]
    pub metrics: Option<MetricsSnapshot>,

    /// Middleware state and statistics
    #[serde(skip_serializing_if = "Option::is_none")]
    pub middleware: Option<MiddlewareStats>,

    /// Service level indicators
    #[serde(skip_serializing_if = "Option::is_none")]
    pub sli: Option<SliSnapshot>,

    /// Custom observability data
    #[serde(skip_serializing_if = "Option::is_none")]
    pub custom: Option<Value>,
}

/// Snapshot of metrics at event creation time
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MetricsSnapshot {
    pub events_processed: u64,
    pub events_in_flight: u32,
    pub queue_depth: u32,
    pub processing_rate: f64,
    pub error_rate: f64,
    pub latency_p50_ms: f64,
    pub latency_p99_ms: f64,
}

/// Middleware statistics
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MiddlewareStats {
    pub timing_ms: u64,
    pub retry_count: u32,
    pub circuit_breaker_state: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub rate_limit_remaining: Option<u32>,
}

/// Service level indicator snapshot
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SliSnapshot {
    pub availability: f64,
    pub error_budget_remaining: f64,
    pub latency_budget_used: f64,
}