Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: collect error log and panic with sentry #514

Merged
merged 2 commits into from
Dec 28, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
125 changes: 125 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions crates/block-producer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ hex = "0.4"
async-trait = "0.1"
semver = "1.0"
rayon = "1.5"
sentry = "0.23.0"
sentry-log = "0.23.0"

[target.'cfg(all(not(target_env = "msvc"), not(target_os="macos")))'.dependencies]
tikv-jemallocator = { version = "0.4.0", features = ["unprefixed_malloc_on_supported_platforms"] }
Expand Down
17 changes: 16 additions & 1 deletion crates/block-producer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use clap::{App, Arg, SubCommand};
use gw_block_producer::{db_block_validator, runner};
use gw_config::Config;
use gw_version::Version;
use sentry_log::LogFilter;
use std::{fs, path::Path};

const COMMAND_RUN: &str = "run";
Expand Down Expand Up @@ -127,6 +128,20 @@ fn run_cli() -> Result<()> {

/// Godwoken entry
fn main() {
env_logger::init_from_env(env_logger::Env::default().default_filter_or("info"));
init_log();
run_cli().expect("run cli");
}

fn init_log() {
let logger = env_logger::builder()
.parse_env(env_logger::Env::default().default_filter_or("info"))
.build();
let level = logger.filter();
let logger = sentry_log::SentryLogger::with_dest(logger).filter(|md| match md.level() {
log::Level::Error => LogFilter::Event,
jjyr marked this conversation as resolved.
Show resolved Hide resolved
_ => LogFilter::Ignore,
});
log::set_boxed_logger(Box::new(logger))
.map(|()| log::set_max_level(level))
.expect("set log");
}
11 changes: 11 additions & 0 deletions crates/block-producer/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,17 @@ impl BaseInitComponents {
}

pub fn run(config: Config, skip_config_check: bool) -> Result<()> {
// Set up sentry.
let _guard = match &config.sentry_dsn.as_ref() {
Some(sentry_dsn) => sentry::init((
sentry_dsn.as_str(),
sentry::ClientOptions {
release: sentry::release_name!(),
..Default::default()
},
)),
None => sentry::init(()),
zeroqn marked this conversation as resolved.
Show resolved Hide resolved
};
// Enable smol threads before smol::spawn
let runtime_threads = match std::env::var(SMOL_THREADS_ENV_VAR) {
Ok(s) => s.parse()?,
Expand Down
1 change: 1 addition & 0 deletions crates/config/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pub struct Config {
pub store: StoreConfig,
#[serde(default)]
pub fee: FeeConfig,
pub sentry_dsn: Option<String>,
}

#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, Hash)]
Expand Down
1 change: 1 addition & 0 deletions crates/tools/src/generate_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ pub fn generate_node_config(args: GenerateNodeConfigArgs) -> Result<Config> {
db_block_validator: Default::default(),
store,
fee: Default::default(),
sentry_dsn: None,
};

Ok(config)
Expand Down