mirror of
https://gitlab.computer.surgery/matrix/grapevine.git
synced 2025-12-17 15:51:23 +01:00
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:
parent
5fca67054e
commit
d28135f7ca
1 changed files with 113 additions and 0 deletions
|
|
@ -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,
|
||||||
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue