Skip to content

[WIP] add sentry integration #1152

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

Closed
wants to merge 1 commit 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
211 changes: 209 additions & 2 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ exclude = [
]

[dependencies]
sentry = { version = "0.20", features = ["env_logger", "log"] }
log = "0.4"
regex = "1"
structopt = "0.3"
Expand Down
25 changes: 19 additions & 6 deletions src/bin/cratesfyi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,28 @@ use docs_rs::{
};
use failure::{err_msg, Error, ResultExt};
use once_cell::sync::OnceCell;
use sentry::integrations::failure::capture_error;
use sentry::integrations::log::LogIntegration;
use structopt::StructOpt;
use strum::VariantNames;

pub fn main() {
let _ = dotenv::dotenv();
logger_init();
//rustwide::logging::init_with(logger_init());
let sentry_log = LogIntegration::default().with_env_logger_dest(Some(logger_init()));
let _guard = sentry::init((
"TODO: fill this in with the secret from https://sentry.io/organizations/rust-lang/",
sentry::ClientOptions {
release: Some(docs_rs::BUILD_VERSION.into()),
..Default::default()
}
.add_integration(sentry_log),
));
log::info!("this is a log from the main thread");
log::error!("this is an error from the main thread");

if let Err(err) = CommandLine::from_args().handle_args() {
capture_error(&err);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would we want sentry on all CLI usage, or only for the web server?

let mut msg = format!("Error: {}", err);
for cause in err.iter_causes() {
write!(msg, "\n\nCaused by:\n {}", cause).unwrap();
Expand All @@ -31,11 +45,12 @@ pub fn main() {
}
}

fn logger_init() {
// NOTE: this function should be idempotent
fn logger_init() -> env_logger::Logger {
use std::io::Write;

let env = env_logger::Env::default().filter_or("DOCSRS_LOG", "docs_rs=info");
let logger = env_logger::from_env(env)
env_logger::from_env(env)
.format(|buf, record| {
writeln!(
buf,
Expand All @@ -46,9 +61,7 @@ fn logger_init() {
record.args()
)
})
.build();

rustwide::logging::init_with(logger);
.build()
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, strum::EnumString, strum::EnumVariantNames)]
Expand Down