-
Notifications
You must be signed in to change notification settings - Fork 221
/
sentry_config.rs
36 lines (30 loc) · 1.04 KB
/
sentry_config.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
use build_info::{get_version, Version};
use serde_derive::Deserialize;
#[derive(Clone, Debug, PartialEq, Deserialize)]
pub struct SentryConfig {
pub dsn: String,
}
impl SentryConfig {
pub fn init(&self) -> sentry::internals::ClientInitGuard {
let version = get_version!();
let guard = sentry::init(self.build_sentry_client_options(&version));
if guard.is_enabled() {
sentry::configure_scope(|scope| {
scope.set_tag("release.pre", version.is_pre());
scope.set_tag("release.dirty", version.is_dirty());
});
sentry::integrations::panic::register_panic_handler();
}
guard
}
pub fn is_enabled(&self) -> bool {
self.dsn.parse::<sentry::internals::Dsn>().is_ok()
}
fn build_sentry_client_options(&self, version: &Version) -> sentry::ClientOptions {
sentry::ClientOptions {
dsn: self.dsn.parse().ok(),
release: Some(version.long().into()),
..Default::default()
}
}
}