1pub mod names {
7 pub const SERVICE: &str = "service";
9 pub const ENVIRONMENT: &str = "environment";
11 pub const COMPONENT: &str = "component";
13 pub const TRACE_ID: &str = "trace_id";
15 pub const SPAN_ID: &str = "span_id";
17 pub const CORRELATION_ID: &str = "correlation_id";
19 pub const USER_ID: &str = "user_id";
21 pub const REQUEST_ID: &str = "request_id";
23 pub const DURATION_MS: &str = "duration_ms";
25 pub const VERSION: &str = "version";
27}
28
29#[cfg(test)]
30mod tests {
31 use super::names::*;
32
33 #[test]
34 fn field_constants_are_non_empty() {
35 let fields = [
36 SERVICE,
37 ENVIRONMENT,
38 COMPONENT,
39 TRACE_ID,
40 SPAN_ID,
41 CORRELATION_ID,
42 USER_ID,
43 REQUEST_ID,
44 DURATION_MS,
45 VERSION,
46 ];
47 for f in fields {
48 assert!(!f.is_empty(), "field constant must not be empty");
49 }
50 }
51
52 #[test]
53 fn field_constants_are_snake_case() {
54 let fields = [
55 SERVICE,
56 ENVIRONMENT,
57 COMPONENT,
58 TRACE_ID,
59 SPAN_ID,
60 CORRELATION_ID,
61 USER_ID,
62 REQUEST_ID,
63 DURATION_MS,
64 VERSION,
65 ];
66 for f in fields {
67 assert!(
68 f.chars().all(|c| c.is_ascii_lowercase() || c == '_'),
69 "field `{f}` must be snake_case"
70 );
71 }
72 }
73}