From bacb3dab7823150c7a49e42bc1b865a92b60b7b9 Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Sun, 13 Oct 2024 00:14:11 -0700 Subject: [PATCH] Prevent lint warnings if internal-logs features is not enabled. (#2196) --- opentelemetry/src/global/internal_logging.rs | 32 ++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/opentelemetry/src/global/internal_logging.rs b/opentelemetry/src/global/internal_logging.rs index 3a5c24ba69..4c09f38b0c 100644 --- a/opentelemetry/src/global/internal_logging.rs +++ b/opentelemetry/src/global/internal_logging.rs @@ -23,12 +23,20 @@ macro_rules! otel_info { { tracing::info!( name: $name, target: env!("CARGO_PKG_NAME"), ""); } + #[cfg(not(feature = "internal-logs"))] + { + let _ = $name; // Compiler will optimize this out as it's unused. + } }; (name: $name:expr, $($key:ident = $value:expr),+ $(,)?) => { #[cfg(feature = "internal-logs")] { tracing::info!(name: $name, target: env!("CARGO_PKG_NAME"), $($key = $value),+, ""); } + #[cfg(not(feature = "internal-logs"))] + { + let _ = ($name, $($value),+); // Compiler will optimize this out as it's unused. + } }; } @@ -50,12 +58,20 @@ macro_rules! otel_warn { { tracing::warn!(name: $name, target: env!("CARGO_PKG_NAME"), ""); } + #[cfg(not(feature = "internal-logs"))] + { + let _ = $name; // Compiler will optimize this out as it's unused. + } }; (name: $name:expr, $($key:ident = $value:expr),+ $(,)?) => { #[cfg(feature = "internal-logs")] { tracing::warn!(name: $name, target: env!("CARGO_PKG_NAME"), $($key = $value),+, ""); } + #[cfg(not(feature = "internal-logs"))] + { + let _ = ($name, $($value),+); // Compiler will optimize this out as it's unused. + } }; } @@ -77,12 +93,20 @@ macro_rules! otel_debug { { tracing::debug!(name: $name, target: env!("CARGO_PKG_NAME"),""); } + #[cfg(not(feature = "internal-logs"))] + { + let _ = $name; // Compiler will optimize this out as it's unused. + } }; (name: $name:expr, $($key:ident = $value:expr),+ $(,)?) => { #[cfg(feature = "internal-logs")] { tracing::debug!(name: $name, target: env!("CARGO_PKG_NAME"), $($key = $value),+, ""); } + #[cfg(not(feature = "internal-logs"))] + { + let _ = ($name, $($value),+); // Compiler will optimize this out as it's unused. + } }; } @@ -104,11 +128,19 @@ macro_rules! otel_error { { tracing::error!(name: $name, target: env!("CARGO_PKG_NAME"), ""); } + #[cfg(not(feature = "internal-logs"))] + { + let _ = $name; // Compiler will optimize this out as it's unused. + } }; (name: $name:expr, $($key:ident = $value:expr),+ $(,)?) => { #[cfg(feature = "internal-logs")] { tracing::error!(name: $name, target: env!("CARGO_PKG_NAME"), $($key = $value),+, ""); } + #[cfg(not(feature = "internal-logs"))] + { + let _ = ($name, $($value),+); // Compiler will optimize this out as it's unused. + } }; }