clnrm_core/telemetry/generated/
mod.rs1pub mod spans {
16 use tracing::{span, Level, Span};
17
18 #[derive(Debug)]
20 pub struct TestExecutionSpan {
21 span: Span,
22 }
23
24 impl TestExecutionSpan {
25 pub fn new(test_name: &str, container_image: &str) -> Self {
26 let span = span!(
27 Level::INFO,
28 "test.execution",
29 test.name = %test_name,
30 container.image = %container_image,
31 );
32 Self { span }
33 }
34
35 pub fn set_isolated(&self, value: bool) -> &Self {
36 self.span.record("test.isolated", value);
37 self
38 }
39
40 pub fn set_result(&self, value: &str) -> &Self {
41 self.span.record("test.result", value);
42 self
43 }
44
45 pub fn enter(&self) -> tracing::span::Entered<'_> {
46 self.span.enter()
47 }
48
49 pub fn span(&self) -> &Span {
50 &self.span
51 }
52
53 pub fn end(self) {
54 drop(self.span);
55 }
56 }
57}
58
59#[cfg(feature = "otel-metrics")]
61pub mod metrics {
62 use opentelemetry::metrics::{Histogram, Meter};
63
64 #[derive(Debug, Clone)]
66 pub struct TestExecutionMetric {
67 histogram: Histogram<f64>,
68 }
69
70 impl TestExecutionMetric {
71 pub fn new(meter: &Meter) -> Self {
72 let histogram = meter
73 .f64_histogram("test.execution.duration")
74 .with_description("Test execution duration in milliseconds")
75 .with_unit("ms")
76 .build();
77 Self { histogram }
78 }
79
80 pub fn record(&self, value: f64, test_name: &str, result: &str) {
81 use opentelemetry::KeyValue;
82 self.histogram.record(
83 value,
84 &[
85 KeyValue::new("test.name", test_name.to_string()),
86 KeyValue::new("test.result", result.to_string()),
87 ],
88 );
89 }
90 }
91}
92
93#[cfg(not(feature = "otel-metrics"))]
94pub mod metrics {
95 #[derive(Debug, Clone)]
97 pub struct TestExecutionMetric;
98
99 impl TestExecutionMetric {
100 pub fn new(_meter: &()) -> Self {
101 Self
102 }
103
104 pub fn record(&self, _value: f64, _test_name: &str, _result: &str) {}
105 }
106}
107
108#[cfg(test)]
110pub mod mocks {
111 use mockall::automock;
112
113 #[automock]
114 pub trait TestExecutionSpanTrait: Send + Sync {
115 fn set_isolated(&self, value: bool);
116 fn set_result(&self, value: String);
117 fn enter(&self);
118 fn end(self: Box<Self>);
119 }
120
121 #[automock]
122 pub trait TestExecutionMetricTrait: Send + Sync {
123 fn record(&self, value: f64, test_name: String, result: String);
124 }
125}
126
127pub mod events {
129 use tracing::{event, Level};
130
131 pub struct TestStartedEvent;
132
133 impl TestStartedEvent {
134 pub fn emit(test_name: &str, container_image: &str) {
135 event!(
136 Level::INFO,
137 test.name = %test_name,
138 container.image = %container_image,
139 "test.started"
140 );
141 }
142 }
143
144 pub struct TestCompletedEvent;
145
146 impl TestCompletedEvent {
147 pub fn emit(test_name: &str, result: &str, duration_ms: f64) {
148 event!(
149 Level::INFO,
150 test.name = %test_name,
151 test.result = %result,
152 test.duration_ms = duration_ms,
153 "test.completed"
154 );
155 }
156 }
157}