From 09a365780f7da3d75ca1f1835f277b616383778b Mon Sep 17 00:00:00 2001 From: Eliza Weisman Date: Tue, 29 Sep 2020 10:54:07 -0700 Subject: [PATCH] macros: fix the `tracing-macros` crate not compiling (#1000) ## Motivation The `tracing-macros` crate doesn't currently compile with the latest `tracing` release, because it uses internal private API that changed. We need to fix this so CI isn't broken. ## Solution I changed the `dbg!` macro so it no longer uses internal APIs. Ideally, we would implement `dbg!` using the support for string-literal field names that was recently added to `tracing`, but I couldn't actually get it to work --- I think the `event!` macros may not handle string literal field names properly (we only test them with the `span!` macros >_>). Will try to fix that later, but for now, this fixes CI and I don't think anyone actually uses the experimental, unreleased `tracing-macros` crate. Signed-off-by: Eliza Weisman --- tracing-macros/src/lib.rs | 42 ++++++++++----------------------------- 1 file changed, 11 insertions(+), 31 deletions(-) diff --git a/tracing-macros/src/lib.rs b/tracing-macros/src/lib.rs index 3a3ccc854f..f554cffd1b 100644 --- a/tracing-macros/src/lib.rs +++ b/tracing-macros/src/lib.rs @@ -1,4 +1,6 @@ #![cfg_attr(docsrs, deny(broken_intra_doc_links))] +#[doc(hidden)] +pub use tracing; /// Alias of `dbg!` for avoiding conflicts with the `std::dbg!` macro. #[macro_export] @@ -10,10 +12,10 @@ macro_rules! trace_dbg { $crate::dbg!(target: module_path!(), level: $level, $ex) }; (target: $target:expr, $ex:expr) => { - $crate::dbg!(target: $target, level: tracing::Level::DEBUG, $ex) + $crate::dbg!(target: $target, level: $crate::tracing::Level::DEBUG, $ex) }; ($ex:expr) => { - $crate::dbg!(level: tracing::Level::DEBUG, $ex) + $crate::dbg!(level: $crate::tracing::Level::DEBUG, $ex) }; } @@ -25,42 +27,20 @@ macro_rules! trace_dbg { #[macro_export] macro_rules! dbg { (target: $target:expr, level: $level:expr, $ex:expr) => {{ - use tracing::callsite::Callsite; - use tracing::{ - callsite, - field::{debug, Value}, - Event, Id, Subscriber, - }; - let callsite = tracing::callsite! { - name: concat!("event:trace_dbg(", stringify!($ex), ")"), - kind: tracing::metadata::Kind::EVENT, - target: $target, - level: $level, - fields: value, - }; - let val = $ex; - if callsite.is_enabled() { - let meta = callsite.metadata(); - let fields = meta.fields(); - let key = meta - .fields() - .into_iter() - .next() - .expect("trace_dbg event must have one field"); - Event::dispatch( - meta, - &fields.value_set(&[(&key, Some(&debug(&val) as &Value))]), - ); + match $ex { + value => { + $crate::tracing::event!(target: $target, $level, ?value, stringify!($ex)); + value + } } - val }}; (level: $level:expr, $ex:expr) => { $crate::dbg!(target: module_path!(), level: $level, $ex) }; (target: $target:expr, $ex:expr) => { - $crate::dbg!(target: $target, level: tracing::Level::DEBUG, $ex) + $crate::dbg!(target: $target, level: $crate::tracing::Level::DEBUG, $ex) }; ($ex:expr) => { - $crate::dbg!(level: tracing::Level::DEBUG, $ex) + $crate::dbg!(level: $crate::tracing::Level::DEBUG, $ex) }; }