integrate sentry with our existing panic reporting logic
This commit is contained in:
parent
f1ec1d626d
commit
400213e2b3
File diff suppressed because it is too large
Load Diff
|
@ -25,4 +25,3 @@ tower = { git = "https://github.com/tower-rs/tower", rev = "d4d1c67c6a0e4213a52a
|
|||
hyper = { git = "https://github.com/hyperium/hyper/", rev = "ed2b22a7f66899d338691552fbcb6c0f2f4e06b9" }
|
||||
metrics = { git = "https://github.com/ZcashFoundation/metrics", rev = "971133128e5aebe3ad177acffc6154449736cfa2" }
|
||||
metrics-exporter-prometheus = { git = "https://github.com/ZcashFoundation/metrics", rev = "971133128e5aebe3ad177acffc6154449736cfa2" }
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ dirs = "3.0.1"
|
|||
inferno = { version = "0.10.2", default-features = false }
|
||||
atty = "0.2.14"
|
||||
|
||||
sentry = { version = "0.21.0", default-features = false, features = ["backtrace", "contexts", "panic", "reqwest", "rustls"] }
|
||||
sentry = { version = "0.21.0", default-features = false, features = ["backtrace", "contexts", "reqwest", "rustls"] }
|
||||
sentry-tracing = { git = "https://github.com/kellpossible/sentry-tracing.git", rev = "f1a4a4a16b5ff1022ae60be779eb3fb928ce9b0f" }
|
||||
|
||||
[build-dependencies]
|
||||
|
|
|
@ -153,7 +153,7 @@ impl Application for ZebradApp {
|
|||
|
||||
// This MUST happen after `Terminal::new` to ensure our preferred panic
|
||||
// handler is the last one installed
|
||||
color_eyre::config::HookBuilder::default()
|
||||
let builder = color_eyre::config::HookBuilder::default()
|
||||
.theme(theme)
|
||||
.issue_url(concat!(env!("CARGO_PKG_REPOSITORY"), "/issues/new"))
|
||||
.add_issue_metadata("version", env!("CARGO_PKG_VERSION"))
|
||||
|
@ -165,9 +165,36 @@ impl Application for ZebradApp {
|
|||
&& !error.is::<tokio::time::error::Elapsed>()
|
||||
&& !error.to_string().contains("timed out")
|
||||
}
|
||||
})
|
||||
.install()
|
||||
.unwrap();
|
||||
});
|
||||
|
||||
let (panic_hook, eyre_hook) = builder.into_hooks();
|
||||
eyre_hook.install().unwrap();
|
||||
|
||||
// The Sentry default config pulls in the DSN from the `SENTRY_DSN`
|
||||
// environment variable.
|
||||
#[cfg(feature = "enable-sentry")]
|
||||
let guard = sentry::init(
|
||||
sentry::ClientOptions {
|
||||
debug: true,
|
||||
..Default::default()
|
||||
}
|
||||
.add_integration(sentry_tracing::TracingIntegration::default()),
|
||||
);
|
||||
|
||||
std::panic::set_hook(Box::new(move |panic_info| {
|
||||
let panic_report = panic_hook.panic_report(panic_info);
|
||||
eprintln!("{}", panic_report);
|
||||
|
||||
#[cfg(feature = "enable-sentry")]
|
||||
{
|
||||
let event = crate::sentry::panic_event_from(panic_report);
|
||||
sentry::capture_event(event);
|
||||
|
||||
if !guard.close(None) {
|
||||
warn!("unable to flush sentry events during panic");
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
self.config = Some(config);
|
||||
|
||||
|
|
|
@ -1,23 +1,11 @@
|
|||
//! Main entry point for Zebrad
|
||||
|
||||
#![deny(warnings, missing_docs, trivial_casts, unused_qualifications)]
|
||||
#![deny(missing_docs, trivial_casts, unused_qualifications)]
|
||||
#![forbid(unsafe_code)]
|
||||
|
||||
use zebrad::application::APPLICATION;
|
||||
|
||||
/// Boot Zebrad
|
||||
fn main() {
|
||||
if cfg!(feature = "enable-sentry") {
|
||||
// The Sentry default config pulls in the DSN from the `SENTRY_DSN`
|
||||
// environment variable.
|
||||
let _guard = sentry::init(
|
||||
sentry::ClientOptions {
|
||||
debug: true,
|
||||
..Default::default()
|
||||
}
|
||||
.add_integration(sentry_tracing::TracingIntegration::default()),
|
||||
);
|
||||
}
|
||||
|
||||
abscissa_core::boot(&APPLICATION);
|
||||
}
|
||||
|
|
|
@ -32,3 +32,4 @@ pub mod application;
|
|||
pub mod commands;
|
||||
pub mod config;
|
||||
pub mod prelude;
|
||||
pub mod sentry;
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
use sentry::{
|
||||
integrations::backtrace::current_stacktrace,
|
||||
protocol::{Event, Exception, Mechanism},
|
||||
};
|
||||
|
||||
pub fn panic_event_from<T>(msg: T) -> Event<'static>
|
||||
where
|
||||
T: ToString,
|
||||
{
|
||||
let exception = Exception {
|
||||
ty: "panic".into(),
|
||||
mechanism: Some(Mechanism {
|
||||
ty: "panic".into(),
|
||||
handled: Some(false),
|
||||
..Default::default()
|
||||
}),
|
||||
value: Some(msg.to_string()),
|
||||
stacktrace: current_stacktrace(),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
Event {
|
||||
exception: vec![exception].into(),
|
||||
level: sentry::Level::Fatal,
|
||||
..Default::default()
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue