From 42e690b907c958e3feaae38bb3b9f97cdf0187c4 Mon Sep 17 00:00:00 2001 From: markhildreth-deepgram <73478513+markhildreth-deepgram@users.noreply.github.com> Date: Wed, 27 Oct 2021 04:26:59 -0400 Subject: [PATCH] Fixed opentelemetry feature breaking due to root_span! use (#51) Fixes https://github.com/LukeMathWalker/tracing-actix-web/issues/50 The `root_span!` macro included some feature flag checks. However, the `root_span!` macro might end up being used in other crates consuming `tracing-actix-web`, and those feature flag checks would be copied in verbatim. The result is that the feature flag checks for things like `opentelemetry_0_14` would actually check the consuming crates flags rather than the flags for `tracing-actix-web`. This commit moves those feature flag checks out of the macro, so they are always resolved against `tracing-actix-web`. --- src/root_span_macro.rs | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/root_span_macro.rs b/src/root_span_macro.rs index 5fae0e400..78a239a44 100644 --- a/src/root_span_macro.rs +++ b/src/root_span_macro.rs @@ -97,12 +97,11 @@ macro_rules! root_span { ); std::mem::drop(connection_info); - #[cfg(any( - feature = "opentelemetry_0_13", - feature = "opentelemetry_0_14", - feature = "opentelemetry_0_15", - feature = "opentelemetry_0_16" - ))] + // Previously, this line was instrumented with an opentelemetry-specific feature + // flag check. However, this resulted in the feature flags being resolved in the crate + // which called `root_span!` as opposed to being resolved by this crate as expected. + // Therefore, this function simply wraps an internal function with the feature flags + // to ensure that the flags are resolved against this crate. $crate::root_span_macro::private::set_otel_parent(&$request, &span); span @@ -123,14 +122,14 @@ pub mod private { pub use tracing; - #[cfg(any( - feature = "opentelemetry_0_13", - feature = "opentelemetry_0_14", - feature = "opentelemetry_0_15", - feature = "opentelemetry_0_16" - ))] #[doc(hidden)] pub fn set_otel_parent(req: &ServiceRequest, span: &tracing::Span) { + #[cfg(any( + feature = "opentelemetry_0_13", + feature = "opentelemetry_0_14", + feature = "opentelemetry_0_15", + feature = "opentelemetry_0_16" + ))] crate::otel::set_otel_parent(req, span); }