zebrad/
sentry.rs

1//! Integration with sentry.io for event reporting.
2//!
3//! Currently handles panic reports.
4
5#[allow(unused_imports)]
6use sentry::{
7    integrations::backtrace::current_stacktrace,
8    protocol::{Event, Exception, Mechanism},
9};
10
11/// Send a panic `msg` to the sentry service.
12pub fn panic_event_from<T>(msg: T) -> Event<'static>
13where
14    T: ToString,
15{
16    let exception = Exception {
17        ty: "panic".into(),
18        mechanism: Some(Mechanism {
19            ty: "panic".into(),
20            handled: Some(false),
21            ..Default::default()
22        }),
23        value: Some(msg.to_string()),
24        // Sentry does not handle panic = abort well yet, and when given this
25        // stacktrace, it consists only of this line, making Sentry dedupe
26        // events together by their stacktrace fingerprint incorrectly.
27        //
28        // stacktrace: current_stacktrace(),
29        ..Default::default()
30    };
31
32    Event {
33        exception: vec![exception].into(),
34        level: sentry::Level::Fatal,
35        ..Default::default()
36    }
37}