mockforge_observability/
lib.rs

1//! MockForge Observability
2//!
3//! Provides comprehensive observability features including:
4//! - Structured logging with JSON support
5//! - Prometheus metrics export
6//! - OpenTelemetry distributed tracing
7//! - Request/response recording (flight recorder)
8//! - Scenario control and chaos engineering
9//! - System metrics collection (CPU, memory, threads)
10//!
11//! # Example
12//!
13//! ```rust
14//! use mockforge_observability::prometheus::MetricsRegistry;
15//!
16//! let registry = MetricsRegistry::new();
17//! registry.record_http_request("GET", 200, 0.045);
18//! ```
19
20pub mod logging;
21pub mod prometheus;
22pub mod system_metrics;
23pub mod tracing_integration;
24
25// Re-export commonly used items
26pub use logging::{init_logging, init_logging_with_otel, LoggingConfig};
27pub use prometheus::{get_global_registry, MetricsRegistry};
28pub use system_metrics::{start_system_metrics_collector, SystemMetricsConfig};
29pub use tracing_integration::{init_with_otel, shutdown_otel, OtelTracingConfig};
30
31/// Protocol types for metrics tracking
32#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
33pub enum Protocol {
34    Http,
35    Grpc,
36    WebSocket,
37    GraphQL,
38}
39
40impl Protocol {
41    pub fn as_str(&self) -> &'static str {
42        match self {
43            Protocol::Http => "http",
44            Protocol::Grpc => "grpc",
45            Protocol::WebSocket => "websocket",
46            Protocol::GraphQL => "graphql",
47        }
48    }
49}
50
51impl std::fmt::Display for Protocol {
52    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
53        write!(f, "{}", self.as_str())
54    }
55}
56
57#[cfg(test)]
58mod tests {
59    use super::*;
60
61    #[test]
62    fn test_protocol_display() {
63        assert_eq!(Protocol::Http.to_string(), "http");
64        assert_eq!(Protocol::Grpc.to_string(), "grpc");
65        assert_eq!(Protocol::WebSocket.to_string(), "websocket");
66        assert_eq!(Protocol::GraphQL.to_string(), "graphql");
67    }
68}