Skip to content

Commit

Permalink
feat(core): make sentry optional
Browse files Browse the repository at this point in the history
  • Loading branch information
Grvzard committed Sep 25, 2024
1 parent 8ae4ebb commit 606cd31
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
7 changes: 4 additions & 3 deletions pingora-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ sentry = { version = "0.26", features = [
"panic",
"reqwest",
"rustls",
], default-features = false }
], default-features = false, optional = true }
regex = "1"
percent-encoding = "2.1"
parking_lot = { version = "0.12", features = ["arc_lock"] }
Expand Down Expand Up @@ -85,8 +85,9 @@ hyperlocal = "0.8"
jemallocator = "0.5"

[features]
default = ["openssl"]
default = ["openssl", "sentry"]
openssl = ["pingora-openssl", "some_tls"]
boringssl = ["pingora-boringssl", "some_tls"]
patched_http1 = []
some_tls = []
some_tls = []
sentry = ["dep:sentry"]
13 changes: 9 additions & 4 deletions pingora-core/src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use daemon::daemonize;
use log::{debug, error, info, warn};
use pingora_runtime::Runtime;
use pingora_timeout::fast_timeout;
#[cfg(feature = "sentry")]
use sentry::ClientOptions;
use std::sync::Arc;
use std::thread;
Expand Down Expand Up @@ -70,6 +71,8 @@ pub struct Server {
/// The Sentry ClientOptions.
///
/// Panics and other events sentry captures will be sent to this DSN **only in release mode**
#[cfg(feature = "sentry")]
#[cfg_attr(docsrs, doc(cfg(feature = "sentry")))]
pub sentry: Option<ClientOptions>,
}

Expand Down Expand Up @@ -116,7 +119,7 @@ impl Server {
Err(e) => {
error!("Unable to send listener sockets to new process: {e}");
// sentry log error on fd send failure
#[cfg(not(debug_assertions))]
#[cfg(all(not(debug_assertions), feature = "sentry"))]
sentry::capture_error(&e);
}
}
Expand Down Expand Up @@ -191,6 +194,7 @@ impl Server {
shutdown_recv: rx,
configuration: Arc::new(conf),
options: Some(opt),
#[cfg(feature = "sentry")]
sentry: None,
}
}
Expand Down Expand Up @@ -231,6 +235,7 @@ impl Server {
shutdown_recv: rx,
configuration: Arc::new(conf),
options: opt,
#[cfg(feature = "sentry")]
sentry: None,
})
}
Expand All @@ -256,7 +261,7 @@ impl Server {
debug!("{:#?}", self.options);

/* only init sentry in release builds */
#[cfg(not(debug_assertions))]
#[cfg(all(not(debug_assertions), feature = "sentry"))]
let _guard = self.sentry.as_ref().map(|opts| sentry::init(opts.clone()));

if self.options.as_ref().map_or(false, |o| o.test) {
Expand All @@ -271,7 +276,7 @@ impl Server {
}
Err(e) => {
// sentry log error on fd load failure
#[cfg(not(debug_assertions))]
#[cfg(all(not(debug_assertions), feature = "sentry"))]
sentry::capture_error(&e);

error!("Bootstrap failed on error: {:?}, exiting.", e);
Expand Down Expand Up @@ -300,7 +305,7 @@ impl Server {
}

/* only init sentry in release builds */
#[cfg(not(debug_assertions))]
#[cfg(all(not(debug_assertions), feature = "sentry"))]
let _guard = self.sentry.as_ref().map(|opts| sentry::init(opts.clone()));

let mut runtimes: Vec<Runtime> = Vec::new();
Expand Down

0 comments on commit 606cd31

Please sign in to comment.