Skip to content

Commit

Permalink
tracing: fix span macros with log feature
Browse files Browse the repository at this point in the history
Fixes the span macro to only substitute the field expressions once when
the log feature is enabled. This stops enabling the log feature causing
"use of moved value" errors and other odd behaviour.
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# On branch macros-with-log
# Your branch is up to date with 'origin/macros-with-log'.
#
# Changes to be committed:
#	modified:   ../tracing/src/macros.rs
#
# Changes not staged for commit:
#	modified:   Cargo.toml
#
# Untracked files:
#	examples/log-move.rs
#
  • Loading branch information
Skepfyr committed Jan 9, 2022
1 parent 874a462 commit bc81ef5
Showing 1 changed file with 32 additions and 35 deletions.
67 changes: 32 additions & 35 deletions tracing/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,22 @@ macro_rules! span {
fields: $($fields)*
};
let mut interest = $crate::collect::Interest::never();
if $crate::level_enabled!($lvl)
&& { interest = CALLSITE.interest(); !interest.is_never() }
&& CALLSITE.is_enabled(interest)
{
let meta = CALLSITE.metadata();
// span with explicit parent
$crate::Span::child_of(
$parent,
meta,
&$crate::valueset!(meta.fields(), $($fields)*),
)
} else {
let span = CALLSITE.disabled_span();
$crate::if_log_enabled! { $lvl, {
span.record_all(&$crate::valueset!(CALLSITE.metadata().fields(), $($fields)*));
}};
span
}
(|value_set| {
if $crate::level_enabled!($lvl)
&& { interest = CALLSITE.interest(); !interest.is_never() }
&& CALLSITE.is_enabled(interest)
{
let meta = CALLSITE.metadata();
// span with explicit parent
$crate::Span::child_of($parent, meta, &value_set)
} else {
let span = CALLSITE.disabled_span();
$crate::if_log_enabled! { $lvl, {
span.record_all(&value_set);
}};
span
}
})($crate::valueset!(CALLSITE.metadata().fields(), $($fields)*))
}
};
(target: $target:expr, $lvl:expr, $name:expr, $($fields:tt)*) => {
Expand All @@ -64,23 +62,22 @@ macro_rules! span {
};

let mut interest = $crate::collect::Interest::never();
if $crate::level_enabled!($lvl)
&& { interest = CALLSITE.interest(); !interest.is_never() }
&& CALLSITE.is_enabled(interest)
{
let meta = CALLSITE.metadata();
// span with contextual parent
$crate::Span::new(
meta,
&$crate::valueset!(meta.fields(), $($fields)*),
)
} else {
let span = CALLSITE.disabled_span();
$crate::if_log_enabled! { $lvl, {
span.record_all(&$crate::valueset!(CALLSITE.metadata().fields(), $($fields)*));
}};
span
}
(|value_set| {
if $crate::level_enabled!($lvl)
&& { interest = CALLSITE.interest(); !interest.is_never() }
&& CALLSITE.is_enabled(interest)
{
let meta = CALLSITE.metadata();
// span with contextual parent
$crate::Span::new(meta, &value_set)
} else {
let span = CALLSITE.disabled_span();
$crate::if_log_enabled! { $lvl, {
span.record_all(&value_set);
}};
span
}
})($crate::valueset!(CALLSITE.metadata().fields(), $($fields)*))
}
};
(target: $target:expr, parent: $parent:expr, $lvl:expr, $name:expr) => {
Expand Down

0 comments on commit bc81ef5

Please sign in to comment.