-
Maybe there is already a clean solution for this. If so, please link so I can read about it. Issue
fn foo() -> Result<Bar, anyhow::Error> {
do_something_failable_1()
.map_err(|e| {
error!("{e:?}"); // report error to current span
e
})?;
do_something_failable_2()
.map_err(|e| {
error!("{e:?}"); // report error to current span
e
})?;
foo_bar()
} Is there a simpler way to report errors on the current span? It's starting to look like go code 😆 Motivation
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
best I could do so far... /// Usage:
/// something_failable().map_err(trace_err)?;
pub fn trace_err<E>(e: E) -> anyhow::Error
where
E: Into<anyhow::Error>,
{
let out = e.into();
error!("{:?}", &out);
out
} |
Beta Was this translation helpful? Give feedback.
-
Naively, if you're writing to jaeger, you're probably using I think that'll handle both conciseness and reporting to Jaeger? |
Beta Was this translation helpful? Give feedback.
-
The #[tracing::instrument(err)]
fn do_something() -> anyhow::Result<()> {
// ...
} If you're using However, this will only work if you want to have a span generated for that function as well. If you're recording spans using the It occurs to me, though, that we could probably add a new attribute in the |
Beta Was this translation helpful? Give feedback.
The
#[instrument]
attribute macro has the ability to automatically record an event when the annotated function returns an error, like this:If you're using
#[instrument]
to generate spans, you can use this attribute to automatically emit events for errors returned byinstrument
ed functions.However, this will only work if you want to have a span generated for that function as well. If you're recording spans using the
span!
macros, or if the functions which you want to record error events from do not have their own spans but are instead inside the span of a calling function, you may not want to use#[instrume…