relay_log::sentry

Function event_from_error

pub fn event_from_error<E>(err: &E) -> Event<'static>
where E: Error + ?Sized,
Expand description

Create a sentry Event from a std::error::Error.

A chain of errors will be resolved as well, and sorted oldest to newest, as described in the sentry event payloads.

ยงExamples

use thiserror::Error;

#[derive(Debug, Error)]
#[error("inner")]
struct InnerError;

#[derive(Debug, Error)]
#[error("outer")]
struct OuterError(#[from] InnerError);

let event = sentry::event_from_error(&OuterError(InnerError));
assert_eq!(event.level, sentry::protocol::Level::Error);
assert_eq!(event.exception.len(), 2);
assert_eq!(&event.exception[0].ty, "InnerError");
assert_eq!(event.exception[0].value, Some("inner".into()));
assert_eq!(&event.exception[1].ty, "OuterError");
assert_eq!(event.exception[1].value, Some("outer".into()));