From 7d618d0c5e3bcfd12af95163376ba8fd44b0ebea Mon Sep 17 00:00:00 2001 From: lcian Date: Fri, 6 Jun 2025 12:55:10 +0200 Subject: [PATCH] refactor(logs): remove UNSTABLE prefix from feature flag --- CHANGELOG.md | 2 +- sentry-core/Cargo.toml | 2 +- sentry-core/src/client.rs | 24 ++++++++++++------------ sentry-core/src/clientoptions.rs | 14 +++++++------- sentry-core/src/hub.rs | 2 +- sentry-core/src/lib.rs | 4 ++-- sentry-core/src/scope/noop.rs | 4 ++-- sentry-core/src/scope/real.rs | 4 ++-- sentry/Cargo.toml | 2 +- sentry/tests/test_basic.rs | 10 +++++----- 10 files changed, 34 insertions(+), 34 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8a2f997d..1b15c546 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ ### Features Support for [Sentry structured logs](https://docs.sentry.io/product/explore/logs/) has been added to the SDK. -- To set up logs, enable the `UNSTABLE_logs` feature of the `sentry` crate and set `enable_logs` to `true` in your client options. +- To set up logs, enable the `logs` feature of the `sentry` crate and set `enable_logs` to `true` in your client options. - Then, use the `logger_trace!`, `logger_debug!`, `logger_info!`, `logger_warn!`, `logger_error!` and `logger_fatal!` macros to capture logs. - To filter or update logs before they are sent, you can use the `before_send_log` client option. - Please note that breaking changes could occur until the API is finalized. diff --git a/sentry-core/Cargo.toml b/sentry-core/Cargo.toml index 784571a2..f3a143cb 100644 --- a/sentry-core/Cargo.toml +++ b/sentry-core/Cargo.toml @@ -24,7 +24,7 @@ default = [] client = ["rand"] test = ["client", "release-health"] release-health = [] -UNSTABLE_logs = [] +logs = [] [dependencies] log = { version = "0.4.8", optional = true, features = ["std"] } diff --git a/sentry-core/src/client.rs b/sentry-core/src/client.rs index 469f7b70..c9abf6b2 100644 --- a/sentry-core/src/client.rs +++ b/sentry-core/src/client.rs @@ -11,7 +11,7 @@ use rand::random; use sentry_types::random_uuid; use crate::constants::SDK_INFO; -#[cfg(feature = "UNSTABLE_logs")] +#[cfg(feature = "logs")] use crate::logs::LogsBatcher; use crate::protocol::{ClientSdkInfo, Event}; #[cfg(feature = "release-health")] @@ -20,7 +20,7 @@ use crate::types::{Dsn, Uuid}; #[cfg(feature = "release-health")] use crate::SessionMode; use crate::{ClientOptions, Envelope, Hub, Integration, Scope, Transport}; -#[cfg(feature = "UNSTABLE_logs")] +#[cfg(feature = "logs")] use sentry_types::protocol::v7::{Log, LogAttribute}; impl> From for Client { @@ -53,7 +53,7 @@ pub struct Client { transport: TransportArc, #[cfg(feature = "release-health")] session_flusher: RwLock>, - #[cfg(feature = "UNSTABLE_logs")] + #[cfg(feature = "logs")] logs_batcher: RwLock>, integrations: Vec<(TypeId, Arc)>, pub(crate) sdk_info: ClientSdkInfo, @@ -78,7 +78,7 @@ impl Clone for Client { self.options.session_mode, ))); - #[cfg(feature = "UNSTABLE_logs")] + #[cfg(feature = "logs")] let logs_batcher = RwLock::new(if self.options.enable_logs { Some(LogsBatcher::new(transport.clone())) } else { @@ -90,7 +90,7 @@ impl Clone for Client { transport, #[cfg(feature = "release-health")] session_flusher, - #[cfg(feature = "UNSTABLE_logs")] + #[cfg(feature = "logs")] logs_batcher, integrations: self.integrations.clone(), sdk_info: self.sdk_info.clone(), @@ -161,7 +161,7 @@ impl Client { options.session_mode, ))); - #[cfg(feature = "UNSTABLE_logs")] + #[cfg(feature = "logs")] let logs_batcher = RwLock::new(if options.enable_logs { Some(LogsBatcher::new(transport.clone())) } else { @@ -173,7 +173,7 @@ impl Client { transport, #[cfg(feature = "release-health")] session_flusher, - #[cfg(feature = "UNSTABLE_logs")] + #[cfg(feature = "logs")] logs_batcher, integrations, sdk_info, @@ -349,7 +349,7 @@ impl Client { if let Some(ref flusher) = *self.session_flusher.read().unwrap() { flusher.flush(); } - #[cfg(feature = "UNSTABLE_logs")] + #[cfg(feature = "logs")] if let Some(ref batcher) = *self.logs_batcher.read().unwrap() { batcher.flush(); } @@ -370,7 +370,7 @@ impl Client { pub fn close(&self, timeout: Option) -> bool { #[cfg(feature = "release-health")] drop(self.session_flusher.write().unwrap().take()); - #[cfg(feature = "UNSTABLE_logs")] + #[cfg(feature = "logs")] drop(self.logs_batcher.write().unwrap().take()); let transport_opt = self.transport.write().unwrap().take(); if let Some(transport) = transport_opt { @@ -395,7 +395,7 @@ impl Client { } /// Captures a log and sends it to Sentry. - #[cfg(feature = "UNSTABLE_logs")] + #[cfg(feature = "logs")] pub fn capture_log(&self, log: Log, scope: &Scope) { if !self.options().enable_logs { return; @@ -409,7 +409,7 @@ impl Client { /// Prepares a log to be sent, setting the `trace_id` and other default attributes, and /// processing it through `before_send_log`. - #[cfg(feature = "UNSTABLE_logs")] + #[cfg(feature = "logs")] fn prepare_log(&self, mut log: Log, scope: &Scope) -> Option { scope.apply_to_log(&mut log, self.options.send_default_pii); @@ -422,7 +422,7 @@ impl Client { Some(log) } - #[cfg(feature = "UNSTABLE_logs")] + #[cfg(feature = "logs")] fn set_log_default_attributes(&self, log: &mut Log) { if !log.attributes.contains_key("sentry.environment") { if let Some(environment) = self.options.environment.as_ref() { diff --git a/sentry-core/src/clientoptions.rs b/sentry-core/src/clientoptions.rs index a741cf43..a3407788 100644 --- a/sentry-core/src/clientoptions.rs +++ b/sentry-core/src/clientoptions.rs @@ -5,7 +5,7 @@ use std::time::Duration; use crate::constants::USER_AGENT; use crate::performance::TracesSampler; -#[cfg(feature = "UNSTABLE_logs")] +#[cfg(feature = "logs")] use crate::protocol::Log; use crate::protocol::{Breadcrumb, Event}; use crate::types::Dsn; @@ -147,7 +147,7 @@ pub struct ClientOptions { /// Callback that is executed for each Breadcrumb being added. pub before_breadcrumb: Option>, /// Callback that is executed for each Log being added. - #[cfg(feature = "UNSTABLE_logs")] + #[cfg(feature = "logs")] pub before_send_log: Option>, // Transport options /// The transport to use. @@ -171,7 +171,7 @@ pub struct ClientOptions { /// server integrations. Needs `send_default_pii` to be enabled to have any effect. pub max_request_body_size: MaxRequestBodySize, /// Determines whether captured structured logs should be sent to Sentry (defaults to false). - #[cfg(feature = "UNSTABLE_logs")] + #[cfg(feature = "logs")] pub enable_logs: bool, // Other options not documented in Unified API /// Disable SSL verification. @@ -232,7 +232,7 @@ impl fmt::Debug for ClientOptions { #[derive(Debug)] struct BeforeBreadcrumb; let before_breadcrumb = self.before_breadcrumb.as_ref().map(|_| BeforeBreadcrumb); - #[cfg(feature = "UNSTABLE_logs")] + #[cfg(feature = "logs")] let before_send_log = { #[derive(Debug)] struct BeforeSendLog; @@ -279,7 +279,7 @@ impl fmt::Debug for ClientOptions { .field("auto_session_tracking", &self.auto_session_tracking) .field("session_mode", &self.session_mode); - #[cfg(feature = "UNSTABLE_logs")] + #[cfg(feature = "logs")] debug_struct .field("enable_logs", &self.enable_logs) .field("before_send_log", &before_send_log); @@ -325,9 +325,9 @@ impl Default for ClientOptions { trim_backtraces: true, user_agent: Cow::Borrowed(USER_AGENT), max_request_body_size: MaxRequestBodySize::Medium, - #[cfg(feature = "UNSTABLE_logs")] + #[cfg(feature = "logs")] enable_logs: false, - #[cfg(feature = "UNSTABLE_logs")] + #[cfg(feature = "logs")] before_send_log: None, } } diff --git a/sentry-core/src/hub.rs b/sentry-core/src/hub.rs index fe246078..ebd70b0c 100644 --- a/sentry-core/src/hub.rs +++ b/sentry-core/src/hub.rs @@ -247,7 +247,7 @@ impl Hub { } /// Captures a structured log. - #[cfg(feature = "UNSTABLE_logs")] + #[cfg(feature = "logs")] pub fn capture_log(&self, log: Log) { with_client_impl! {{ let top = self.inner.with(|stack| stack.top().clone()); diff --git a/sentry-core/src/lib.rs b/sentry-core/src/lib.rs index 1649c66a..a39e63ca 100644 --- a/sentry-core/src/lib.rs +++ b/sentry-core/src/lib.rs @@ -132,7 +132,7 @@ pub use crate::intodsn::IntoDsn; pub use crate::performance::*; pub use crate::scope::{Scope, ScopeGuard}; pub use crate::transport::{Transport, TransportFactory}; -#[cfg(feature = "UNSTABLE_logs")] +#[cfg(feature = "logs")] mod logger; // structured logging macros exported with `#[macro_export]` // client feature @@ -140,7 +140,7 @@ mod logger; // structured logging macros exported with `#[macro_export]` mod client; #[cfg(feature = "client")] mod hub_impl; -#[cfg(all(feature = "client", feature = "UNSTABLE_logs"))] +#[cfg(all(feature = "client", feature = "logs"))] mod logs; #[cfg(feature = "client")] mod session; diff --git a/sentry-core/src/scope/noop.rs b/sentry-core/src/scope/noop.rs index 578c1f9b..fc62120b 100644 --- a/sentry-core/src/scope/noop.rs +++ b/sentry-core/src/scope/noop.rs @@ -1,6 +1,6 @@ use std::fmt; -#[cfg(feature = "UNSTABLE_logs")] +#[cfg(feature = "logs")] use crate::protocol::Log; use crate::protocol::{Context, Event, Level, User, Value}; use crate::TransactionOrSpan; @@ -113,7 +113,7 @@ impl Scope { } /// Applies the contained scoped data to fill a log. - #[cfg(feature = "UNSTABLE_logs")] + #[cfg(feature = "logs")] pub fn apply_to_log(&self, log: &mut Log) { let _log = log; minimal_unreachable!(); diff --git a/sentry-core/src/scope/real.rs b/sentry-core/src/scope/real.rs index c8147ce0..f4972cf1 100644 --- a/sentry-core/src/scope/real.rs +++ b/sentry-core/src/scope/real.rs @@ -9,7 +9,7 @@ use crate::performance::TransactionOrSpan; use crate::protocol::{ Attachment, Breadcrumb, Context, Event, Level, TraceContext, Transaction, User, Value, }; -#[cfg(feature = "UNSTABLE_logs")] +#[cfg(feature = "logs")] use crate::protocol::{Log, LogAttribute}; #[cfg(feature = "release-health")] use crate::session::Session; @@ -350,7 +350,7 @@ impl Scope { /// Applies the contained scoped data to a log, setting the `trace_id` and certain default /// attributes. - #[cfg(feature = "UNSTABLE_logs")] + #[cfg(feature = "logs")] pub fn apply_to_log(&self, log: &mut Log, send_default_pii: bool) { if let Some(span) = self.span.as_ref() { log.trace_id = Some(span.get_trace_context().trace_id); diff --git a/sentry/Cargo.toml b/sentry/Cargo.toml index 9ab7e315..7737c31a 100644 --- a/sentry/Cargo.toml +++ b/sentry/Cargo.toml @@ -48,7 +48,7 @@ opentelemetry = ["sentry-opentelemetry"] # other features test = ["sentry-core/test"] release-health = ["sentry-core/release-health", "sentry-actix?/release-health"] -UNSTABLE_logs = ["sentry-core/UNSTABLE_logs"] +logs = ["sentry-core/logs"] # transports transport = ["reqwest", "native-tls"] reqwest = ["dep:reqwest", "httpdate", "tokio"] diff --git a/sentry/tests/test_basic.rs b/sentry/tests/test_basic.rs index fb80c90d..8f5f4d0b 100644 --- a/sentry/tests/test_basic.rs +++ b/sentry/tests/test_basic.rs @@ -265,7 +265,7 @@ fn test_panic_scope_pop() { ); } -#[cfg(feature = "UNSTABLE_logs")] +#[cfg(feature = "logs")] #[test] fn test_basic_capture_log() { use std::time::SystemTime; @@ -314,7 +314,7 @@ fn test_basic_capture_log() { } } -#[cfg(feature = "UNSTABLE_logs")] +#[cfg(feature = "logs")] #[test] fn test_basic_capture_log_macro_message() { use sentry_core::logger_info; @@ -349,7 +349,7 @@ fn test_basic_capture_log_macro_message() { } } -#[cfg(feature = "UNSTABLE_logs")] +#[cfg(feature = "logs")] #[test] fn test_basic_capture_log_macro_message_formatted() { use sentry::protocol::LogAttribute; @@ -416,7 +416,7 @@ fn test_basic_capture_log_macro_message_formatted() { } } -#[cfg(feature = "UNSTABLE_logs")] +#[cfg(feature = "logs")] #[test] fn test_basic_capture_log_macro_message_with_attributes() { use sentry::protocol::LogAttribute; @@ -475,7 +475,7 @@ fn test_basic_capture_log_macro_message_with_attributes() { } } -#[cfg(feature = "UNSTABLE_logs")] +#[cfg(feature = "logs")] #[test] fn test_basic_capture_log_macro_message_formatted_with_attributes() { use sentry::protocol::LogAttribute;