From 78dfd8999d81a54b98ccf9bb277fe8b45e0f490f Mon Sep 17 00:00:00 2001 From: Alejandro Cabeza Romero Date: Thu, 19 Dec 2024 16:14:18 +0100 Subject: [PATCH] Feature gate instrument macro. --- Cargo.toml | 2 +- overwatch-rs/Cargo.toml | 1 + overwatch-rs/src/overwatch/handle.rs | 5 ++--- overwatch-rs/src/overwatch/mod.rs | 2 +- overwatch-rs/src/services/relay.rs | 4 ++-- overwatch-rs/src/services/settings.rs | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 0f461ca..4b81df0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,4 +7,4 @@ members = [ [profile.release-opt] inherits = "release" -lto = true \ No newline at end of file +lto = true diff --git a/overwatch-rs/Cargo.toml b/overwatch-rs/Cargo.toml index 8a58460..b88f94b 100644 --- a/overwatch-rs/Cargo.toml +++ b/overwatch-rs/Cargo.toml @@ -21,6 +21,7 @@ exclude = [ [features] default = ["derive"] derive = ["dep:overwatch-derive"] +instrumentation = [] [dependencies] overwatch-derive = { path = "../overwatch-derive", optional = true } diff --git a/overwatch-rs/src/overwatch/handle.rs b/overwatch-rs/src/overwatch/handle.rs index fe64876..eb3a7a1 100644 --- a/overwatch-rs/src/overwatch/handle.rs +++ b/overwatch-rs/src/overwatch/handle.rs @@ -62,14 +62,13 @@ impl OverwatchHandle { } /// Send an overwatch command to the overwatch runner - #[instrument(name = "overwatch-command-send", skip(self))] + #[cfg_attr(feature = "instrumentation", instrument(name = "overwatch-command-send", skip(self)))] pub async fn send(&self, command: OverwatchCommand) { if let Err(e) = self.sender.send(command).await { error!(error=?e, "Error sending overwatch command"); } } - - #[instrument(skip(self))] + #[cfg_attr(feature = "instrumentation", instrument(skip(self)))] pub async fn update_settings(&self, settings: S::Settings) where S::Settings: Send, diff --git a/overwatch-rs/src/overwatch/mod.rs b/overwatch-rs/src/overwatch/mod.rs index 74456b4..b2d6810 100644 --- a/overwatch-rs/src/overwatch/mod.rs +++ b/overwatch-rs/src/overwatch/mod.rs @@ -142,7 +142,7 @@ where }) } - #[instrument(name = "overwatch-run", skip_all)] + #[cfg_attr(feature = "instrumentation", instrument(name = "overwatch-run", skip_all))] async fn run_(self, mut receiver: Receiver) { let Self { mut services, diff --git a/overwatch-rs/src/services/relay.rs b/overwatch-rs/src/services/relay.rs index bbe2a83..282ca0d 100644 --- a/overwatch-rs/src/services/relay.rs +++ b/overwatch-rs/src/services/relay.rs @@ -164,7 +164,7 @@ impl Relay { } } - #[instrument(skip(self), err(Debug))] + #[cfg_attr(feature = "instrumentation", instrument(skip(self), err(Debug)))] pub async fn connect(self) -> Result, RelayError> { let (reply, receiver) = oneshot::channel(); self.request_relay(reply).await; @@ -179,7 +179,7 @@ impl Relay { self.overwatch_handle.send(relay_command).await; } - #[instrument(skip_all, err(Debug))] + #[cfg_attr(feature = "instrumentation", instrument(skip_all, err(Debug)))] async fn handle_relay_response( &self, receiver: oneshot::Receiver, diff --git a/overwatch-rs/src/services/settings.rs b/overwatch-rs/src/services/settings.rs index 0644ac0..34a13c7 100644 --- a/overwatch-rs/src/services/settings.rs +++ b/overwatch-rs/src/services/settings.rs @@ -41,7 +41,7 @@ impl SettingsUpdater { } /// Send a new settings update notification to the watcher end - #[instrument(skip_all)] + #[cfg_attr(feature = "instrumentation", instrument(skip_all))] pub fn update(&self, settings: S) { self.sender.send(settings).unwrap_or_else(|_e| { error!("Error sending settings update for service");