opentelemetry_spanprocessor_any/sdk/resource/
os.rs1use crate::sdk::resource::ResourceDetector;
5use crate::sdk::Resource;
6use crate::KeyValue;
7use std::env::consts::OS;
8use std::time::Duration;
9
10#[derive(Debug)]
18pub struct OsResourceDetector;
19
20impl ResourceDetector for OsResourceDetector {
21 fn detect(&self, _timeout: Duration) -> Resource {
22 Resource::new(vec![KeyValue::new("os.type", OS)])
23 }
24}
25
26#[cfg(target_os = "linux")]
27#[cfg(test)]
28mod tests {
29 use crate::sdk::resource::os::OsResourceDetector;
30 use crate::sdk::resource::ResourceDetector;
31 use crate::Key;
32 use std::time::Duration;
33
34 #[test]
35 fn test_os_resource_detector() {
36 let resource = OsResourceDetector.detect(Duration::from_secs(0));
37 assert_eq!(
38 resource
39 .iter()
40 .0
41 .find(|(k, _v)| **k == Key::from_static_str("os.type"))
42 .map(|(_k, v)| v.to_string()),
43 Some("linux".to_string())
44 );
45 }
46}