Skip to content

fix: use release-health flag in sentry-actix and remove it from subcrates where unneeded #787

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

Merged
merged 7 commits into from
May 8, 2025
Merged
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
21 changes: 14 additions & 7 deletions sentry-actix/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,18 +284,24 @@ where
));

let client = hub.client();
let track_sessions = client.as_ref().is_some_and(|client| {
let options = client.options();
options.auto_session_tracking
&& options.session_mode == sentry_core::SessionMode::Request
});

let max_request_body_size = client
.as_ref()
.map(|client| client.options().max_request_body_size)
.unwrap_or(MaxRequestBodySize::None);
if track_sessions {
hub.start_session();

#[cfg(feature = "release-health")]
{
let track_sessions = client.as_ref().is_some_and(|client| {
let options = client.options();
options.auto_session_tracking
&& options.session_mode == sentry_core::SessionMode::Request
});
if track_sessions {
hub.start_session();
}
}

let with_pii = client
.as_ref()
.is_some_and(|client| client.options().send_default_pii);
Expand Down Expand Up @@ -673,6 +679,7 @@ mod tests {
assert_eq!(request.method, Some("GET".into()));
}

#[cfg(feature = "release-health")]
#[actix_web::test]
async fn test_track_session() {
let envelopes = sentry::test::with_captured_envelopes_options(
Expand Down
22 changes: 13 additions & 9 deletions sentry-core/src/clientoptions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,14 +174,10 @@ pub struct ClientOptions {
/// When automatic session tracking is enabled, a new "user-mode" session
/// is started at the time of `sentry::init`, and will persist for the
/// application lifetime.
///
/// **NOTE**: The `release-health` feature (enabled by default) needs to be enabled for this option to have
/// any effect.
#[cfg(feature = "release-health")]
pub auto_session_tracking: bool,
/// Determine how Sessions are being tracked.
///
/// **NOTE**: The `release-health` feature (enabled by default) needs to be enabled for this option to have
/// any effect.
#[cfg(feature = "release-health")]
pub session_mode: SessionMode,
/// Border frames which indicate a border from a backtrace to
/// useless internals. Some are automatically included.
Expand Down Expand Up @@ -232,7 +228,8 @@ impl fmt::Debug for ClientOptions {

let integrations: Vec<_> = self.integrations.iter().map(|i| i.name()).collect();

f.debug_struct("ClientOptions")
let mut debug_struct = f.debug_struct("ClientOptions");
debug_struct
.field("dsn", &self.dsn)
.field("debug", &self.debug)
.field("release", &self.release)
Expand Down Expand Up @@ -260,9 +257,14 @@ impl fmt::Debug for ClientOptions {
.field("http_proxy", &self.http_proxy)
.field("https_proxy", &self.https_proxy)
.field("shutdown_timeout", &self.shutdown_timeout)
.field("accept_invalid_certs", &self.accept_invalid_certs)
.field("accept_invalid_certs", &self.accept_invalid_certs);

#[cfg(feature = "release-health")]
debug_struct
.field("auto_session_tracking", &self.auto_session_tracking)
.field("session_mode", &self.session_mode)
.field("session_mode", &self.session_mode);

debug_struct
.field("extra_border_frames", &self.extra_border_frames)
.field("trim_backtraces", &self.trim_backtraces)
.field("user_agent", &self.user_agent)
Expand Down Expand Up @@ -295,7 +297,9 @@ impl Default for ClientOptions {
https_proxy: None,
shutdown_timeout: Duration::from_secs(2),
accept_invalid_certs: false,
#[cfg(feature = "release-health")]
auto_session_tracking: false,
#[cfg(feature = "release-health")]
session_mode: SessionMode::Application,
extra_border_frames: vec![],
trim_backtraces: true,
Expand Down
7 changes: 0 additions & 7 deletions sentry-core/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@ mod session_impl {
SessionStatus, SessionUpdate,
};

#[cfg(feature = "release-health")]
use crate::scope::StackLayer;

#[cfg(feature = "release-health")]
use crate::types::random_uuid;
use crate::{Client, Envelope};

Expand All @@ -45,7 +43,6 @@ mod session_impl {
}

impl Session {
#[cfg(feature = "release-health")]
pub fn from_stack(stack: &StackLayer) -> Option<Self> {
let client = stack.client.as_ref()?;
let options = client.options();
Expand Down Expand Up @@ -121,7 +118,6 @@ mod session_impl {
}
}

#[cfg(feature = "release-health")]
pub(crate) fn create_envelope_item(&mut self) -> Option<EnvelopeItem> {
if self.dirty {
let item = self.session_update.clone().into();
Expand All @@ -135,7 +131,6 @@ mod session_impl {

// as defined here: https://develop.sentry.dev/sdk/envelopes/#size-limits
const MAX_SESSION_ITEMS: usize = 100;
#[cfg(feature = "release-health")]
const FLUSH_INTERVAL: Duration = Duration::from_secs(60);

#[derive(Debug, Default)]
Expand Down Expand Up @@ -202,7 +197,6 @@ mod session_impl {

impl SessionFlusher {
/// Creates a new Flusher that will submit envelopes to the given `transport`.
#[cfg(feature = "release-health")]
pub fn new(transport: TransportArc, mode: SessionMode) -> Self {
let queue = Arc::new(Mutex::new(Default::default()));
#[allow(clippy::mutex_atomic)]
Expand Down Expand Up @@ -464,7 +458,6 @@ mod session_impl {
},
crate::ClientOptions {
release: Some("some-release".into()),
#[cfg(feature = "release-health")]
session_mode: SessionMode::Request,
..Default::default()
},
Expand Down
1 change: 0 additions & 1 deletion sentry-opentelemetry/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ all-features = true
[dependencies]
sentry-core = { version = "0.37.0", path = "../sentry-core", features = [
"client",
"release-health"
] }
opentelemetry = { version = "0.29.0", default-features = false }
opentelemetry_sdk = { version = "0.29.0", default-features = false, features = [
Expand Down
3 changes: 1 addition & 2 deletions sentry-tower/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ rust-version = "1.81"
all-features = true

[features]
default = ["release-health"]
default = []
http = ["dep:http", "pin-project", "url"]
axum-matched-path = ["http", "axum/matched-path"]
release-health = ["sentry-core/release-health"]

[dependencies]
axum = { version = "0.8", optional = true, default-features = false }
Expand Down
3 changes: 1 addition & 2 deletions sentry-tracing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ rust-version = "1.81"
all-features = true

[features]
default = ["release-health"]
default = []
backtrace = ["dep:sentry-backtrace"]
release-health = ["sentry-core/release-health"]

[dependencies]
sentry-core = { version = "0.37.0", path = "../sentry-core", features = [
Expand Down
4 changes: 2 additions & 2 deletions sentry/src/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ where
{
let opts = apply_defaults(opts.into());

#[allow(unused)]
#[cfg(feature = "release-health")]
let auto_session_tracking = opts.auto_session_tracking;
#[allow(unused)]
#[cfg(feature = "release-health")]
let session_mode = opts.session_mode;

let client = Arc::new(Client::from(opts));
Expand Down