pub mod names {
pub const SERVICE: &str = "service";
pub const ENVIRONMENT: &str = "environment";
pub const COMPONENT: &str = "component";
pub const TRACE_ID: &str = "trace_id";
pub const SPAN_ID: &str = "span_id";
pub const CORRELATION_ID: &str = "correlation_id";
pub const USER_ID: &str = "user_id";
pub const REQUEST_ID: &str = "request_id";
pub const DURATION_MS: &str = "duration_ms";
pub const VERSION: &str = "version";
}
#[cfg(test)]
mod tests {
use super::names::*;
#[test]
fn field_constants_are_non_empty() {
let fields = [
SERVICE,
ENVIRONMENT,
COMPONENT,
TRACE_ID,
SPAN_ID,
CORRELATION_ID,
USER_ID,
REQUEST_ID,
DURATION_MS,
VERSION,
];
for f in fields {
assert!(!f.is_empty(), "field constant must not be empty");
}
}
#[test]
fn field_constants_are_snake_case() {
let fields = [
SERVICE,
ENVIRONMENT,
COMPONENT,
TRACE_ID,
SPAN_ID,
CORRELATION_ID,
USER_ID,
REQUEST_ID,
DURATION_MS,
VERSION,
];
for f in fields {
assert!(
f.chars().all(|c| c.is_ascii_lowercase() || c == '_'),
"field `{f}` must be snake_case"
);
}
}
}