Skip to main content

backbone_observability/
config.rs

1//! Configuration management for Backbone Framework Observability
2
3use serde::{Deserialize, Serialize};
4
5/// Observability configuration
6#[derive(Debug, Clone, Deserialize, Serialize)]
7pub struct ObservabilityConfig {
8    /// Enable distributed tracing
9    pub tracing_enabled: bool,
10
11    /// Default log level (trace, debug, info, warn, error)
12    pub log_level: String,
13
14    /// OpenTelemetry endpoint (e.g., Jaeger, OTLP)
15    pub otlp_endpoint: Option<String>,
16
17    /// Service name for tracing
18    pub service_name: String,
19
20    /// Structured logging configuration
21    pub logging: LoggingConfig,
22}
23
24impl Default for ObservabilityConfig {
25    fn default() -> Self {
26        Self {
27            tracing_enabled: true,
28            log_level: "info".to_string(),
29            otlp_endpoint: None,
30            service_name: "backbone-app".to_string(),
31            logging: LoggingConfig::default(),
32        }
33    }
34}
35
36/// Structured logging configuration
37#[derive(Debug, Clone, Deserialize, Serialize)]
38pub struct LoggingConfig {
39    /// Enable JSON structured logging
40    pub json_format: bool,
41
42    /// Include timestamp in all logs
43    pub include_timestamp: bool,
44
45    /// Include hostname in all logs
46    pub include_hostname: bool,
47
48    /// Include span context
49    pub include_spans: bool,
50
51    /// Field names to extract as top-level fields
52    pub extract_fields: Vec<String>,
53
54    /// Buffer size for log aggregation
55    pub buffer_size: usize,
56}
57
58impl Default for LoggingConfig {
59    fn default() -> Self {
60        Self {
61            json_format: true,
62            include_timestamp: true,
63            include_hostname: true,
64            include_spans: true,
65            extract_fields: vec![
66                "user_id".to_string(),
67                "request_id".to_string(),
68                "module".to_string(),
69                "action".to_string(),
70            ],
71            buffer_size: 1000,
72        }
73    }
74}
75
76/// Metrics configuration
77#[derive(Debug, Clone, Deserialize, Serialize)]
78pub struct MetricsConfig {
79    /// Enable metrics collection
80    pub enabled: bool,
81
82    /// Metrics exporter type
83    pub exporter: MetricsExporterType,
84
85    /// Metrics export port (for Prometheus)
86    pub port: u16,
87}
88
89impl Default for MetricsConfig {
90    fn default() -> Self {
91        Self {
92            enabled: false,
93            exporter: MetricsExporterType::Stdout,
94            port: 9090,
95        }
96    }
97}
98
99/// Metrics exporter type
100#[derive(Debug, Clone, Deserialize, Serialize)]
101#[serde(rename_all = "lowercase")]
102pub enum MetricsExporterType {
103    /// Export to stdout (logging)
104    Stdout,
105
106    /// Export via Prometheus endpoint
107    Prometheus,
108}