add helper macros to log error source chains

The specific thing that prompted this is that Error::Reqwest only logs
the Display impl of reqwest::Error, while the actual information you
need to determine what went wrong is usually buried deeper in the source
chain. This makes debugging federation networking issues super
frustrating.

Instead of just fixing this one case, let's just log the source chains
everywhere. What could go wrong?
This commit is contained in:
Olivia Lee 2024-12-13 22:30:48 -08:00
parent 5fca67054e
commit d28135f7ca
No known key found for this signature in database
GPG key ID: 54D568A15B9CD1F9

View file

@ -11,3 +11,116 @@
pub(crate) use tracing as t; pub(crate) use tracing as t;
pub(crate) use tracing::Instrument; 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,
};