From 2ef888d1008820f74aed59f65b37a025c7fb2190 Mon Sep 17 00:00:00 2001 From: Rio Kierkels Date: Tue, 30 Jun 2020 14:42:16 +0200 Subject: [PATCH] chore(sentry): make sentry dsn customizable By removing the hardcoded value the sentry client will fall back to pulling it from the SENTRY_DSN environment variable. The hardcoded value has been moved to the default value of the commandline options so the default behavior will be the same. A `--no-sentry` and `MEILI_NO_SENTRY` option has also been introduced that effectively disables sentry reporting. --- meilisearch-http/src/main.rs | 28 ++++++++++++++++++++-------- meilisearch-http/src/option.rs | 11 +++++++++++ 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/meilisearch-http/src/main.rs b/meilisearch-http/src/main.rs index d7edcce6d..997df92ac 100644 --- a/meilisearch-http/src/main.rs +++ b/meilisearch-http/src/main.rs @@ -4,7 +4,7 @@ use actix_cors::Cors; use actix_web::{middleware, HttpServer}; use main_error::MainError; use meilisearch_http::helpers::NormalizePath; -use meilisearch_http::{Data, Opt, create_app, index_update_callback}; +use meilisearch_http::{create_app, index_update_callback, Data, Opt}; use structopt::StructOpt; mod analytics; @@ -19,7 +19,11 @@ async fn main() -> Result<(), MainError> { #[cfg(all(not(debug_assertions), feature = "sentry"))] let _sentry = sentry::init(( - "https://5ddfa22b95f241198be2271aaf028653@sentry.io/3060337", + if !opt.no_sentry { + Some(opt.sentry_dsn.clone()) + } else { + None + }, sentry::ClientOptions { release: sentry::release_name!(), ..Default::default() @@ -36,8 +40,8 @@ async fn main() -> Result<(), MainError> { } #[cfg(all(not(debug_assertions), feature = "sentry"))] - if !opt.no_analytics { - sentry::integrations::panic::register_panic_handler(); + if !opt.no_sentry && _sentry.is_enabled() { + sentry::integrations::panic::register_panic_handler(); // TODO: This shouldn't be needed when upgrading to sentry 0.19.0. These integrations are turned on by default when using `sentry::init`. sentry::integrations::env_logger::init(None, Default::default()); } } @@ -52,9 +56,7 @@ async fn main() -> Result<(), MainError> { if !opt.no_analytics { let analytics_data = data.clone(); let analytics_opt = opt.clone(); - thread::spawn(move|| { - analytics::analytics_sender(analytics_data, analytics_opt) - }); + thread::spawn(move || analytics::analytics_sender(analytics_data, analytics_opt)); } let data_cloned = data.clone(); @@ -69,7 +71,7 @@ async fn main() -> Result<(), MainError> { .wrap( Cors::new() .send_wildcard() - .allowed_headers(vec!["content-type","x-meili-api-key"]) + .allowed_headers(vec!["content-type", "x-meili-api-key"]) .max_age(86_400) // 24h .finish(), ) @@ -117,6 +119,16 @@ pub fn print_launch_resume(opt: &Opt, data: &Data) { env!("CARGO_PKG_VERSION").to_string() ); + #[cfg(all(not(debug_assertions), feature = "sentry"))] + eprintln!( + "Sentry DSN:\t\t{:?}", + if !opt.no_sentry { + &opt.sentry_dsn + } else { + "Disabled" + } + ); + eprintln!(); if data.api_keys.master.is_some() { diff --git a/meilisearch-http/src/option.rs b/meilisearch-http/src/option.rs index f8d9170b1..aefb71b07 100644 --- a/meilisearch-http/src/option.rs +++ b/meilisearch-http/src/option.rs @@ -26,6 +26,17 @@ pub struct Opt { #[structopt(long, env = "MEILI_MASTER_KEY")] pub master_key: Option, + /// The Sentry DSN to use for error reporting. This defaults to the MeiliSearch Sentry project. + /// You can disable sentry all together using the `--no-sentry` flag or `MEILI_NO_SENTRY` environment variable. + #[cfg(all(not(debug_assertions), feature = "sentry"))] + #[structopt(long, env = "SENTRY_DSN", default_value = "https://5ddfa22b95f241198be2271aaf028653@sentry.io/3060337")] + pub sentry_dsn: String, + + /// Disable Sentry error reporting. + #[cfg(all(not(debug_assertions), feature = "sentry"))] + #[structopt(long, env = "MEILI_NO_SENTRY")] + pub no_sentry: bool, + /// This environment variable must be set to `production` if your are running in production. /// If the server is running in development mode more logs will be displayed, /// and the master key can be avoided which implies that there is no security on the updates routes.