Skip to content

Commit

Permalink
chore: add sentry tags
Browse files Browse the repository at this point in the history
  • Loading branch information
doitian committed Apr 14, 2019
1 parent 554ba4e commit e452c64
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
14 changes: 8 additions & 6 deletions src/setup/sentry_config.rs
Expand Up @@ -9,8 +9,14 @@ pub struct SentryConfig {

impl SentryConfig {
pub fn init(&self) -> sentry::internals::ClientInitGuard {
let guard = sentry::init(self);
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();
info!(target: "sentry", "**Notice**: \
The ckb process will send stack trace to sentry on Rust panics. \
Expand All @@ -22,12 +28,8 @@ impl SentryConfig {

guard
}
}

impl<'a> Into<sentry::ClientOptions> for &'a SentryConfig {
fn into(self) -> sentry::ClientOptions {
let version = get_version!();

fn build_sentry_client_options(&self, version: &Version) -> sentry::ClientOptions {
sentry::ClientOptions {
dsn: self.dsn.parse().ok(),
release: Some(version.long().into()),
Expand Down
14 changes: 13 additions & 1 deletion util/build-info/src/lib.rs
Expand Up @@ -59,6 +59,18 @@ impl Version {
pub fn long(&self) -> String {
format!("{}", self)
}

pub fn is_pre(&self) -> bool {
self.dash_pre != ""
}

pub fn is_dirty(&self) -> bool {
if let Some(describe) = &self.commit_describe {
describe.ends_with("-dirty")
} else {
false
}
}
}

impl std::fmt::Display for Version {
Expand Down Expand Up @@ -93,7 +105,7 @@ pub fn get_channel() -> Option<String> {

pub fn get_commit_describe() -> Option<String> {
std::process::Command::new("git")
.args(&["describe", "--dirty=dev"])
.args(&["describe", "--dirty"])
.output()
.ok()
.and_then(|r| String::from_utf8(r.stdout).ok())
Expand Down

0 comments on commit e452c64

Please sign in to comment.