mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-30 08:44:27 +01:00
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.
This commit is contained in:
parent
4e1e41994c
commit
2ef888d100
@ -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() {
|
||||||
|
@ -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.
|
||||||
|
Loading…
Reference in New Issue
Block a user