grapevine/src/observability/prelude.rs
2025-03-22 14:34:04 -07:00

125 lines
3.5 KiB
Rust

//! Common tracing-related items intended to be wildcard imported in most
//! modules:
//!
//! ```
//! use crate::observability::prelude::*;
//! ```
//!
//! This avoids diff churn in the imports when adding/removing log statements.
//!
//! [`tracing`] is re-exported as `t`, to avoid name collisions.
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.
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,
};