mockforge_observability/
tracing_integration.rs1use crate::logging::LoggingConfig;
7
8#[derive(Debug, Clone)]
10pub struct OtelTracingConfig {
11 pub service_name: String,
13 pub environment: String,
15 pub jaeger_endpoint: Option<String>,
17 pub otlp_endpoint: Option<String>,
19 pub protocol: String,
21 pub sampling_rate: f64,
23}
24
25impl Default for OtelTracingConfig {
26 fn default() -> Self {
27 Self {
28 service_name: "mockforge".to_string(),
29 environment: "development".to_string(),
30 jaeger_endpoint: Some("http://localhost:14268/api/traces".to_string()),
31 otlp_endpoint: Some("http://localhost:4317".to_string()),
32 protocol: "grpc".to_string(),
33 sampling_rate: 1.0,
34 }
35 }
36}
37
38#[cfg(feature = "opentelemetry")]
69pub fn init_with_otel(
70 logging_config: LoggingConfig,
71 _tracing_config: OtelTracingConfig,
72) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
73 tracing::warn!("OpenTelemetry integration requires mockforge-tracing crate");
78 crate::logging::init_logging(logging_config)?;
79
80 Ok(())
81}
82
83#[cfg(feature = "opentelemetry")]
85pub fn shutdown_otel() {
86 tracing::info!("Shutting down OpenTelemetry tracer");
88}
89
90#[cfg(not(feature = "opentelemetry"))]
91pub fn init_with_otel(
92 logging_config: LoggingConfig,
93 _tracing_config: OtelTracingConfig,
94) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
95 tracing::warn!("OpenTelemetry feature not enabled, using standard logging");
96 crate::logging::init_logging(logging_config)?;
97 Ok(())
98}
99
100#[cfg(not(feature = "opentelemetry"))]
101pub fn shutdown_otel() {
102 }
104
105#[cfg(test)]
106mod tests {
107 use super::*;
108
109 #[test]
110 fn test_default_otel_config() {
111 let config = OtelTracingConfig::default();
112 assert_eq!(config.service_name, "mockforge");
113 assert_eq!(config.environment, "development");
114 assert_eq!(config.sampling_rate, 1.0);
115 assert_eq!(config.protocol, "grpc");
116 }
117
118 #[test]
119 fn test_custom_otel_config() {
120 let config = OtelTracingConfig {
121 service_name: "test-service".to_string(),
122 environment: "production".to_string(),
123 jaeger_endpoint: Some("http://jaeger:14268/api/traces".to_string()),
124 otlp_endpoint: Some("http://otel:4317".to_string()),
125 protocol: "http".to_string(),
126 sampling_rate: 0.5,
127 };
128
129 assert_eq!(config.service_name, "test-service");
130 assert_eq!(config.environment, "production");
131 assert_eq!(config.sampling_rate, 0.5);
132 }
133}