From 81ceb65008892826f3a813e9029a4e678beff87a Mon Sep 17 00:00:00 2001 From: Michael Wigard Date: Tue, 5 Sep 2023 19:18:40 +0200 Subject: [PATCH] attributes: fix instrument with "log" feature (#2599) ## Motivation The instrument macro currently doesn't work with the "log" crate feature: #2585 ## Solution Change the generated code to create a span if either `tracing::if_log_enabled!` or `tracing::level_enabled!`. I'm not sure how to add a test for this or if this is the best solution. Fixes #2585 --- tracing-attributes/src/expand.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tracing-attributes/src/expand.rs b/tracing-attributes/src/expand.rs index bedff8e833..2a55bd0f7f 100644 --- a/tracing-attributes/src/expand.rs +++ b/tracing-attributes/src/expand.rs @@ -343,7 +343,7 @@ fn gen_block( // regression in case the level is enabled. let __tracing_attr_span; let __tracing_attr_guard; - if tracing::level_enabled!(#level) { + if tracing::level_enabled!(#level) || tracing::if_log_enabled!(#level, {true} else {false}) { __tracing_attr_span = #span; #follows_from __tracing_attr_guard = __tracing_attr_span.enter();