Skip to content

Commit

Permalink
Adding location to record_exception, to have final raise location gua…
Browse files Browse the repository at this point in the history
…ranteed, can often lose useful info when everything is propagating anyerr.
  • Loading branch information
zakstucke committed Jul 9, 2024
1 parent 63963d2 commit b70a2c4
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion rust/bitbazaar/log/global_log/global_fns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,21 @@ use parking_lot::{MappedMutexGuard, MutexGuard};
use super::{out::GLOBAL_LOG, GlobalLog};
use crate::prelude::*;

/// Record an exception to the currently active span.
/// Record an exception to the currently active span, making sure the record location is added to the stacktrace.
/// Matches oltp spec so it shows up correctly as an exception in observers
/// <https://opentelemetry.io/docs/specs/semconv/exceptions/exceptions-spans/>
///
/// Arguments:
/// - `message`: Information about the exception e.g. `Internal Error leading to 500 http response`.
/// - `stacktrace`: All of the location information for the exception, (maybe also the exception itself if e.g. from `Report<T>`).
#[track_caller]
pub fn record_exception(message: impl Into<String>, stacktrace: impl Into<String>) {
let mut stacktrace = stacktrace.into();
stacktrace = if stacktrace.trim().is_empty() {
format!("At {}", std::panic::Location::caller())
} else {
format!("{}\nAt {}", stacktrace, std::panic::Location::caller())
};
super::exceptions::record_exception_inner(message, stacktrace, "Err");
}

Expand Down

0 comments on commit b70a2c4

Please sign in to comment.