1use serde::{Deserialize, Serialize};
7use std::collections::HashMap;
8
9#[derive(Debug, Clone, Serialize, Deserialize)]
11pub struct TelemetryConfig {
12 pub enabled: bool,
14 pub service_name: String,
16 pub service_version: String,
18 pub exporters: Vec<ExporterConfig>,
20 pub sampling: SamplingConfig,
22 pub resource_attributes: HashMap<String, String>,
24}
25
26impl Default for TelemetryConfig {
27 fn default() -> Self {
28 Self {
29 enabled: false,
30 service_name: "clnrm".to_string(),
31 service_version: "1.0.0".to_string(),
32 exporters: vec![ExporterConfig::Stdout { pretty_print: true }],
33 sampling: SamplingConfig::default(),
34 resource_attributes: HashMap::new(),
35 }
36 }
37}
38
39#[derive(Debug, Clone, Serialize, Deserialize)]
41pub enum ExporterConfig {
42 Otlp {
44 endpoint: String,
46 protocol: OtlpProtocol,
48 headers: HashMap<String, String>,
50 },
51 Jaeger {
53 endpoint: String,
55 agent_host: Option<String>,
57 agent_port: Option<u16>,
59 },
60 Zipkin {
62 endpoint: String,
64 },
65 Stdout {
67 pretty_print: bool,
69 },
70}
71
72#[derive(Debug, Clone, Serialize, Deserialize)]
74pub enum OtlpProtocol {
75 HttpProto,
77 Grpc,
79}
80
81impl Default for OtlpProtocol {
82 fn default() -> Self {
83 Self::HttpProto
84 }
85}
86
87#[derive(Debug, Clone, Serialize, Deserialize)]
89pub struct SamplingConfig {
90 pub trace_sampling_ratio: f64,
92 pub parent_based: bool,
94}
95
96impl Default for SamplingConfig {
97 fn default() -> Self {
98 Self {
99 trace_sampling_ratio: 1.0, parent_based: true,
101 }
102 }
103}
104
105#[derive(Debug, Clone, Serialize, Deserialize)]
107pub struct OtelValidationConfig {
108 pub validate_spans: bool,
110 pub validate_traces: bool,
112 pub validate_exports: bool,
114 pub validate_performance: bool,
116}
117
118impl Default for OtelValidationConfig {
119 fn default() -> Self {
120 Self {
121 validate_spans: true,
122 validate_traces: true,
123 validate_exports: true,
124 validate_performance: true,
125 }
126 }
127}
128
129#[derive(Debug, Clone, Serialize, Deserialize)]
131pub struct SpanAssertion {
132 pub name: String,
134 pub required: bool,
136 pub attributes: HashMap<String, String>,
138 pub min_duration_ms: Option<f64>,
140 pub max_duration_ms: Option<f64>,
142}
143
144#[derive(Debug, Clone, Serialize, Deserialize)]
146pub struct TraceAssertion {
147 pub trace_id: Option<String>,
149 pub expected_spans: Vec<SpanAssertion>,
151 pub parent_child_relationships: Vec<ParentChildRelationship>,
153 pub complete: bool,
155}
156
157#[derive(Debug, Clone, Serialize, Deserialize)]
159pub struct ParentChildRelationship {
160 pub parent_span_name: String,
162 pub child_span_name: String,
164}
165
166#[derive(Debug, Clone, Serialize, Deserialize)]
168pub struct SpanValidationResult {
169 pub passed: bool,
171 pub span_name: String,
173 pub errors: Vec<String>,
175 pub actual_attributes: HashMap<String, String>,
177 pub actual_duration_ms: Option<f64>,
179}
180
181#[derive(Debug, Clone, Serialize, Deserialize)]
183pub struct TraceValidationResult {
184 pub passed: bool,
186 pub trace_id: Option<String>,
188 pub expected_span_count: usize,
190 pub actual_span_count: usize,
192 pub span_results: Vec<SpanValidationResult>,
194 pub errors: Vec<String>,
196}