From f8a0cc26817eac3ea1edec8d6eeef5657f583a5a Mon Sep 17 00:00:00 2001 From: Alejandro Cabeza Romero Date: Thu, 19 Dec 2024 16:25:16 +0100 Subject: [PATCH] Feature gate instrument imports on overwatch-derive. --- overwatch-derive/Cargo.toml | 3 +++ overwatch-derive/src/lib.rs | 13 ++++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/overwatch-derive/Cargo.toml b/overwatch-derive/Cargo.toml index 31564c2..a98c374 100644 --- a/overwatch-derive/Cargo.toml +++ b/overwatch-derive/Cargo.toml @@ -21,6 +21,9 @@ exclude = [ [lib] proc-macro = true +[features] +instrumentation = [] + [dependencies] heck = "0.4" syn = "1.0" diff --git a/overwatch-derive/src/lib.rs b/overwatch-derive/src/lib.rs index 8ec3430..281302c 100644 --- a/overwatch-derive/src/lib.rs +++ b/overwatch-derive/src/lib.rs @@ -3,6 +3,8 @@ mod utils; use proc_macro_error::{abort_call_site, proc_macro_error}; use quote::{format_ident, quote}; use syn::{punctuated::Punctuated, token::Comma, Data, DeriveInput, Field, Generics}; +#[cfg(feature = "instrumentation")] +use tracing::instrument; #[proc_macro_derive(Services)] #[proc_macro_error] @@ -185,7 +187,8 @@ fn generate_start_all_impl(fields: &Punctuated) -> proc_macro2::To }); quote! { - #[::tracing::instrument(skip(self), err)] + + #[cfg_attr(feature = "instrumentation", instrument(skip(self), err))] fn start_all(&mut self) -> Result<::overwatch_rs::overwatch::ServicesLifeCycleHandle, ::overwatch_rs::overwatch::Error> { ::std::result::Result::Ok([#( #call_start ),*].try_into()?) } @@ -205,7 +208,7 @@ fn generate_start_impl(fields: &Punctuated) -> proc_macro2::TokenS }); quote! { - #[::tracing::instrument(skip(self), err)] + #[cfg_attr(feature = "instrumentation", instrument(skip(self), err))] fn start(&mut self, service_id: ::overwatch_rs::services::ServiceId) -> Result<(), ::overwatch_rs::overwatch::Error> { match service_id { #( #cases ),* @@ -226,7 +229,7 @@ fn generate_stop_impl(fields: &Punctuated) -> proc_macro2::TokenSt }); quote! { - #[::tracing::instrument(skip(self), err)] + #[cfg_attr(feature = "instrumentation", instrument(skip(self), err))] fn stop(&mut self, service_id: ::overwatch_rs::services::ServiceId) -> Result<(), ::overwatch_rs::overwatch::Error> { match service_id { #( #cases ),* @@ -252,7 +255,7 @@ fn generate_request_relay_impl(fields: &Punctuated) -> proc_macro2 }); quote! { - #[::tracing::instrument(skip(self), err)] + #[cfg_attr(feature = "instrumentation", instrument(skip(self), err))] fn request_relay(&mut self, service_id: ::overwatch_rs::services::ServiceId) -> ::overwatch_rs::services::relay::RelayResult { { match service_id { @@ -282,7 +285,7 @@ fn generate_update_settings_impl(fields: &Punctuated) -> proc_macr }); quote! { - #[::tracing::instrument(skip(self, settings), err)] + #[cfg_attr(feature = "instrumentation", instrument(skip(self, settings), err))] fn update_settings(&mut self, settings: Self::Settings) -> Result<(), ::overwatch_rs::overwatch::Error> { let Self::Settings { #( #fields_settings ),*