Skip to main content

rskit_logging/
fields.rs

1//! Standard field names for the unified log schema.
2//!
3//! These constants ensure consistency across all kits (gokit, rskit, pykit) when emitting structured log fields.
4
5/// Standard field names for the unified log schema.
6pub mod names {
7    /// The service name emitting the log entry.
8    pub const SERVICE: &str = "service";
9    /// Deployment environment (development, staging, production).
10    pub const ENVIRONMENT: &str = "environment";
11    /// Logical component within the service (e.g. "auth", "cache").
12    pub const COMPONENT: &str = "component";
13    /// Distributed trace identifier.
14    pub const TRACE_ID: &str = "trace_id";
15    /// Span identifier within a trace.
16    pub const SPAN_ID: &str = "span_id";
17    /// Correlation identifier for cross-service request tracking.
18    pub const CORRELATION_ID: &str = "correlation_id";
19    /// User identifier.
20    pub const USER_ID: &str = "user_id";
21    /// HTTP request identifier.
22    pub const REQUEST_ID: &str = "request_id";
23    /// Duration of an operation in milliseconds.
24    pub const DURATION_MS: &str = "duration_ms";
25    /// Service version string.
26    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}