From adaf90844576f3f9bd0b48f575b75827774ef724 Mon Sep 17 00:00:00 2001 From: alvarocabanas Date: Wed, 27 Mar 2024 18:25:02 +0100 Subject: [PATCH] Format code --- opentelemetry-resource-detectors/src/host.rs | 46 ++++++++++---------- opentelemetry-resource-detectors/src/lib.rs | 4 +- 2 files changed, 26 insertions(+), 24 deletions(-) diff --git a/opentelemetry-resource-detectors/src/host.rs b/opentelemetry-resource-detectors/src/host.rs index 27638ce3..ba7aaec5 100644 --- a/opentelemetry-resource-detectors/src/host.rs +++ b/opentelemetry-resource-detectors/src/host.rs @@ -1,13 +1,13 @@ //! HOST resource detector //! //! Detect the unique host ID. +use opentelemetry::KeyValue; +use opentelemetry_sdk::resource::ResourceDetector; +use opentelemetry_sdk::Resource; use std::error::Error; use std::fs::read_to_string; use std::path::Path; use std::time::Duration; -use opentelemetry::KeyValue; -use opentelemetry_sdk::Resource; -use opentelemetry_sdk::resource::ResourceDetector; /// Detect the unique host ID. /// @@ -16,25 +16,29 @@ use opentelemetry_sdk::resource::ResourceDetector; /// /// [`host.id from non-containerized systems`]: https://opentelemetry.io/docs/specs/semconv/resource/host/#collecting-hostid-from-non-containerized-systems pub struct HostResourceDetector { - host_id_detect: fn() -> Option + host_id_detect: fn() -> Option, } impl ResourceDetector for HostResourceDetector { fn detect(&self, _timeout: Duration) -> Resource { - (self.host_id_detect)().map(|host_id| { - Resource::new(vec![KeyValue::new( - opentelemetry_semantic_conventions::resource::HOST_ID, - host_id, - )]) - }).unwrap_or(Resource::new(vec![])) + (self.host_id_detect)() + .map(|host_id| { + Resource::new(vec![KeyValue::new( + opentelemetry_semantic_conventions::resource::HOST_ID, + host_id, + )]) + }) + .unwrap_or(Resource::new(vec![])) } } #[cfg(target_os = "linux")] fn host_id_detect() -> Option { - let machine_id_path = Path::new("/etc/machine-id"); + let machine_id_path = Path::new("/etc/machine-id"); let dbus_machine_id_path = Path::new("/var/lib/dbus/machine-id"); - read_to_string(machine_id_path).or_else(|_|{read_to_string(dbus_machine_id_path)}).ok() + read_to_string(machine_id_path) + .or_else(|_| read_to_string(dbus_machine_id_path)) + .ok() } // TODO: Implement non-linux platforms @@ -45,28 +49,26 @@ fn host_id_detect() -> Option { impl Default for HostResourceDetector { fn default() -> Self { - Self { - host_id_detect - } + Self { host_id_detect } } } #[cfg(target_os = "linux")] #[cfg(test)] mod tests { - use std::time::Duration; + use super::HostResourceDetector; use opentelemetry::{Key, Value}; use opentelemetry_sdk::resource::ResourceDetector; - use super::HostResourceDetector; + use std::time::Duration; #[test] fn test_host_resource_detector() { - let resource = HostResourceDetector::default().detect(Duration::from_secs(0)); + let resource = HostResourceDetector::default().detect(Duration::from_secs(0)); assert_eq!(resource.len(), 1); - assert!( - resource.get(Key::from_static_str( + assert!(resource + .get(Key::from_static_str( opentelemetry_semantic_conventions::resource::HOST_ID - )).is_some() - ) + )) + .is_some()) } } diff --git a/opentelemetry-resource-detectors/src/lib.rs b/opentelemetry-resource-detectors/src/lib.rs index f8137628..61837690 100644 --- a/opentelemetry-resource-detectors/src/lib.rs +++ b/opentelemetry-resource-detectors/src/lib.rs @@ -6,10 +6,10 @@ //! - [`OsResourceDetector`] - detect OS from runtime. //! - [`ProcessResourceDetector`] - detect process information. //! - [`HostResourceDetector`] - detect unique host ID. +mod host; mod os; mod process; -mod host; +pub use host::HostResourceDetector; pub use os::OsResourceDetector; pub use process::ProcessResourceDetector; -pub use host::HostResourceDetector;