Merge pull request #813 from Rio/remove-hardcoded-sentry-dsn

feat(sentry): make sentry dsn customizable
This commit is contained in:
Clément Renault 2020-07-01 16:15:21 +02:00 committed by GitHub
commit ad267cbe59
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 8 deletions

View File

@ -4,7 +4,7 @@ use actix_cors::Cors;
use actix_web::{middleware, HttpServer}; use actix_web::{middleware, HttpServer};
use main_error::MainError; use main_error::MainError;
use meilisearch_http::helpers::NormalizePath; 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; use structopt::StructOpt;
mod analytics; mod analytics;
@ -19,7 +19,11 @@ async fn main() -> Result<(), MainError> {
#[cfg(all(not(debug_assertions), feature = "sentry"))] #[cfg(all(not(debug_assertions), feature = "sentry"))]
let _sentry = sentry::init(( let _sentry = sentry::init((
"https://5ddfa22b95f241198be2271aaf028653@sentry.io/3060337", if !opt.no_sentry {
Some(opt.sentry_dsn.clone())
} else {
None
},
sentry::ClientOptions { sentry::ClientOptions {
release: sentry::release_name!(), release: sentry::release_name!(),
..Default::default() ..Default::default()
@ -36,8 +40,8 @@ async fn main() -> Result<(), MainError> {
} }
#[cfg(all(not(debug_assertions), feature = "sentry"))] #[cfg(all(not(debug_assertions), feature = "sentry"))]
if !opt.no_analytics { if !opt.no_sentry && _sentry.is_enabled() {
sentry::integrations::panic::register_panic_handler(); 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()); sentry::integrations::env_logger::init(None, Default::default());
} }
} }
@ -52,9 +56,7 @@ async fn main() -> Result<(), MainError> {
if !opt.no_analytics { if !opt.no_analytics {
let analytics_data = data.clone(); let analytics_data = data.clone();
let analytics_opt = opt.clone(); let analytics_opt = opt.clone();
thread::spawn(move|| { thread::spawn(move || analytics::analytics_sender(analytics_data, analytics_opt));
analytics::analytics_sender(analytics_data, analytics_opt)
});
} }
let data_cloned = data.clone(); let data_cloned = data.clone();
@ -69,7 +71,7 @@ async fn main() -> Result<(), MainError> {
.wrap( .wrap(
Cors::new() Cors::new()
.send_wildcard() .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 .max_age(86_400) // 24h
.finish(), .finish(),
) )
@ -117,6 +119,16 @@ pub fn print_launch_resume(opt: &Opt, data: &Data) {
env!("CARGO_PKG_VERSION").to_string() 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!(); eprintln!();
if data.api_keys.master.is_some() { if data.api_keys.master.is_some() {

View File

@ -26,6 +26,17 @@ pub struct Opt {
#[structopt(long, env = "MEILI_MASTER_KEY")] #[structopt(long, env = "MEILI_MASTER_KEY")]
pub master_key: Option<String>, pub master_key: Option<String>,
/// 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. /// 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, /// 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. /// and the master key can be avoided which implies that there is no security on the updates routes.