]> Untitled Git - lemmy.git/blobdiff - crates/utils/src/lib.rs
Add tracing (#1942)
[lemmy.git] / crates / utils / src / lib.rs
index e30150e30b058521986ffece8130fa2313719f1c..5eaff30e80b914e71808e884870a83e9b71b9288 100644 (file)
@@ -16,9 +16,10 @@ pub mod utils;
 pub mod version;
 
 use http::StatusCode;
-use log::warn;
 use std::{fmt, fmt::Display};
 use thiserror::Error;
+use tracing::warn;
+use tracing_error::SpanTrace;
 
 pub type ConnectionId = usize;
 
@@ -66,6 +67,7 @@ impl ApiError {
 #[derive(Debug)]
 pub struct LemmyError {
   pub inner: anyhow::Error,
+  pub context: SpanTrace,
 }
 
 impl<T> From<T> for LemmyError
@@ -73,13 +75,17 @@ where
   T: Into<anyhow::Error>,
 {
   fn from(t: T) -> Self {
-    LemmyError { inner: t.into() }
+    LemmyError {
+      inner: t.into(),
+      context: SpanTrace::capture(),
+    }
   }
 }
 
 impl Display for LemmyError {
   fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
-    self.inner.fmt(f)
+    self.inner.fmt(f)?;
+    self.context.fmt(f)
   }
 }