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

Fix rustsec-2020-0041, upd sentry #178

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
117 changes: 97 additions & 20 deletions Cargo.lock

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

14 changes: 8 additions & 6 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,17 @@ enum-iterator = "0.6.0"
signal-notify = "0.1.3"

[dependencies.sentry]
version = "0.18"
version = "0.20.1"
optional = true
features = [
"with_log",
"with_env_logger",
"with_panic",
# "with_debug_to_log"
"default",
"log",
"env_logger",
"anyhow",
"panic",
# "debug-logs"
]

[features]
default = [ "sentry" ]
integrity-tests = [ "sentry", "sentry/with_test_support" ]
integrity-tests = [ "sentry", "sentry/with_test_support" ] # test
47 changes: 24 additions & 23 deletions cli/src/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ use crate::config::*;
#[cfg(feature = "sentry")]
pub(crate) mod support_sentry {
use super::*;
use sentry::internals::Dsn;
use sentry::internals::ClientInitGuard;
use sentry::integrations::panic::register_panic_handler;
use sentry::integrations::env_logger::init as sentry_log_init;
use sentry::internals::{ClientInitGuard, Dsn};
use sentry::integrations::log::LogIntegration;
use sentry::integrations::panic::PanicIntegration;
pub use sentry::integrations::anyhow::capture_anyhow;

/// Create standard logger, init integrations such as with sentry.
/// At the end init Libra's logger.
Expand All @@ -16,9 +16,9 @@ pub(crate) mod support_sentry {
) -> Option<ClientInitGuard> {
let mut builder = logging_builder(log);
let result = if let Some(sentry_dsn) = &integrations.sentry_dsn {
sentry_log_init(Some(builder.build()), Default::default());
let log = LogIntegration::default().with_env_logger_dest(Some(builder.build()));

let sentry = init_sentry(sentry_dsn, &integrations.sentry_env);
let sentry = init_sentry(sentry_dsn, &integrations.sentry_env, log);
trace!("Logging system initialized with Sentry.");

Some(sentry)
Expand All @@ -43,29 +43,31 @@ pub(crate) mod support_sentry {
/// - register panic handler.
///
/// Returns guard for panic handler and api-client.
pub fn init_sentry(dsn: &Dsn, env: &Option<String>) -> ClientInitGuard {
pub fn init_sentry(dsn: &Dsn, env: &Option<String>, logger: LogIntegration) -> ClientInitGuard {
// back-compat to default env var:
std::env::set_var("SENTRY_DSN", format!("{}", &dsn));

let client = {
let mut options = sentry::ClientOptions::default();
options.dsn = Some(dsn.to_owned());
if let Some(ref env) = env {
trace!("sentry env: {}", env);
options.environment = Some(env.to_owned().into());
}
sentry::init(options)
};
if client.is_enabled() {
register_panic_handler();
trace!("Sentry integration enabled, panic handler registered.");
} else {
trace!("Sentry client disabled");
let mut options = sentry::ClientOptions::default()
// add logging integration
.add_integration(logger)
// add panic handler
.add_integration(PanicIntegration::default());
// set env
if let Some(ref env) = env {
trace!("sentry env: {}", env);
options.environment = Some(env.to_owned().into());
}
client
// set DSN:
options.dsn = Some(dsn.to_owned());
sentry::init(options)
}
}

#[cfg(not(feature = "sentry"))]
pub fn capture_anyhow(e: &anyhow::Error) {
error!("{}", e);
}

mod support_libra_logger {
use libra::logger;
use logger::{StructLogSink, StructuredLogEntry};
Expand All @@ -80,7 +82,6 @@ mod support_libra_logger {
warn!("unable to initialize sub-logger");
})
.ok();
// logger::init_println_struct_log()
}

struct TraceLog;
Expand Down