diff --git a/src/observability/prelude.rs b/src/observability/prelude.rs index a991e8f7..80e328f6 100644 --- a/src/observability/prelude.rs +++ b/src/observability/prelude.rs @@ -11,3 +11,116 @@ pub(crate) use tracing as t; pub(crate) use tracing::Instrument; + +/// [`tracing::event!`] but takes an error and formats its source chain as an +/// `error` field. +/// +/// The `parent:` and `target:` arguments from the original macro are not +/// supported. +#[allow(unused)] +macro_rules! event_err { + ($level:expr, $error:expr, $($rest:tt)+) => { + ::tracing::event!( + $level, + error=%::wee_woo::ErrorExt::display_with_sources(&$error, " -> "), + $($rest)+ + ) + } +} + +/// [`tracing::trace!`] but takes an error and formats its source chain as an +/// `error` field. +/// +/// The `parent:` and `target:` arguments from the original macro are not +/// supported. +// Allowed because all of these variants exist for completeness, even if they +// aren't currently used. +#[allow(unused)] +macro_rules! trace_err { + ($error:expr, $($rest:tt)+) => { + $crate::observability::prelude::event_err!( + ::tracing::Level::TRACE, + $error, + $($rest)+ + ) + } +} + +/// [`tracing::debug!`] but takes an error and formats its source chain as an +/// `error` field. +/// +/// The `parent:` and `target:` arguments from the original macro are not +/// supported. +// Allowed because all of these variants exist for completeness, even if they +// aren't currently used. +#[allow(unused)] +macro_rules! debug_err { + ($error:expr, $($rest:tt)+) => { + $crate::observability::prelude::event_err!( + ::tracing::Level::DEBUG, + $error, + $($rest)+ + ) + } +} + +/// [`tracing::info!`] but takes an error and formats its source chain as an +/// `error` field. +/// +/// The `parent:` and `target:` arguments from the original macro are not +/// supported. +// Allowed because all of these variants exist for completeness, even if they +// aren't currently used. +#[allow(unused)] +macro_rules! info_err { + ($error:expr, $($rest:tt)+) => { + $crate::observability::prelude::event_err!( + ::tracing::Level::INFO, + $error, + $($rest)+ + ) + } +} + +/// [`tracing::warn!`] but takes an error and formats its source chain as an +/// `error` field. +/// +/// The `parent:` and `target:` arguments from the original macro are not +/// supported. +// Allowed because all of these variants exist for completeness, even if they +// aren't currently used. +#[allow(unused)] +macro_rules! warn_err { + ($error:expr, $($rest:tt)+) => { + $crate::observability::prelude::event_err!( + ::tracing::Level::WARN, + $error, + $($rest)+ + ) + } +} + +/// [`tracing::error!`] but takes an error and formats its source chain as an +/// `error` field. +/// +/// The `parent:` and `target:` arguments from the original macro are not +/// supported. +// Allowed because all of these variants exist for completeness, even if they +// aren't currently used. +#[allow(unused)] +macro_rules! error_err { + ($error:expr, $($rest:tt)+) => { + $crate::observability::prelude::event_err!( + ::tracing::Level::ERROR, + $error, + $($rest)+ + ) + } +} + +// Allowed because all of these variants exist for completeness, even if they +// aren't currently used. +#[allow(unused)] +pub(crate) use { + debug_err, error_err, event_err, info_err, trace_err, warn_err, +};