Skip to main content

feagi_observability/
config.rs

1// Copyright 2025 Neuraville Inc.
2// SPDX-License-Identifier: Apache-2.0
3
4//! Observability configuration types
5
6use serde::{Deserialize, Serialize};
7use std::path::PathBuf;
8
9/// Unified observability configuration
10#[derive(Debug, Clone, Serialize, Deserialize)]
11pub struct ObservabilityConfig {
12    pub logging: LoggingConfig,
13    pub telemetry: TelemetryConfig,
14    pub profiling: ProfilingConfig,
15}
16
17/// Logging configuration
18#[derive(Debug, Clone, Serialize, Deserialize)]
19pub struct LoggingConfig {
20    /// Log level (trace, debug, info, warn, error)
21    pub level: String,
22
23    /// Log format (text or json)
24    pub format: LogFormat,
25
26    /// Output destination
27    pub output: LogOutput,
28
29    /// File path (if output is file)
30    pub file_path: Option<PathBuf>,
31}
32
33/// Log format
34#[derive(Debug, Clone, Serialize, Deserialize)]
35pub enum LogFormat {
36    Text,
37    Json,
38}
39
40/// Log output destination
41#[derive(Debug, Clone, Serialize, Deserialize)]
42pub enum LogOutput {
43    Stdout,
44    File(String),
45    Syslog,
46}
47
48/// Telemetry configuration
49#[derive(Debug, Clone, Serialize, Deserialize)]
50pub struct TelemetryConfig {
51    /// Enable Prometheus metrics
52    pub metrics_enabled: bool,
53
54    /// Enable distributed tracing
55    pub tracing_enabled: bool,
56
57    /// Tracing endpoint (Jaeger OTLP)
58    pub tracing_endpoint: Option<String>,
59
60    /// Metrics endpoint path
61    pub metrics_path: String,
62
63    /// Health check endpoint
64    pub health_check_path: String,
65
66    /// System metrics collection interval (seconds)
67    pub system_metrics_interval: u64,
68}
69
70/// Profiling configuration
71#[derive(Debug, Clone, Serialize, Deserialize)]
72pub struct ProfilingConfig {
73    /// Enable CPU profiling
74    pub cpu_profiling: bool,
75
76    /// Enable memory profiling
77    pub memory_profiling: bool,
78
79    /// Output directory for profiles
80    pub output_dir: PathBuf,
81
82    /// Profiling sample rate (0.0-1.0)
83    pub sample_rate: f64,
84
85    /// Enable Chrome DevTools tracing
86    pub chrome_tracing: bool,
87
88    /// Enable perf profiling (Linux only)
89    pub perf_profiling: bool,
90}
91
92impl Default for ObservabilityConfig {
93    fn default() -> Self {
94        ObservabilityConfig {
95            logging: LoggingConfig {
96                level: "info".to_string(),
97                format: LogFormat::Text,
98                output: LogOutput::Stdout,
99                file_path: None,
100            },
101            telemetry: TelemetryConfig {
102                metrics_enabled: true,
103                tracing_enabled: false,
104                tracing_endpoint: None,
105                metrics_path: "/metrics".to_string(),
106                health_check_path: "/health".to_string(),
107                system_metrics_interval: 5,
108            },
109            profiling: ProfilingConfig {
110                cpu_profiling: false,
111                memory_profiling: false,
112                output_dir: PathBuf::from("./profiles"),
113                sample_rate: 1.0,
114                chrome_tracing: false,
115                perf_profiling: false,
116            },
117        }
118    }
119}
120
121impl Default for LoggingConfig {
122    fn default() -> Self {
123        LoggingConfig {
124            level: "info".to_string(),
125            format: LogFormat::Text,
126            output: LogOutput::Stdout,
127            file_path: None,
128        }
129    }
130}
131
132impl Default for TelemetryConfig {
133    fn default() -> Self {
134        TelemetryConfig {
135            metrics_enabled: true,
136            tracing_enabled: false,
137            tracing_endpoint: None,
138            metrics_path: "/metrics".to_string(),
139            health_check_path: "/health".to_string(),
140            system_metrics_interval: 5,
141        }
142    }
143}
144
145impl Default for ProfilingConfig {
146    fn default() -> Self {
147        ProfilingConfig {
148            cpu_profiling: false,
149            memory_profiling: false,
150            output_dir: PathBuf::from("./profiles"),
151            sample_rate: 1.0,
152            chrome_tracing: false,
153            perf_profiling: false,
154        }
155    }
156}