Skip to content

refactor(logs): remove UNSTABLE prefix from feature flag #832

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 2 commits into from
Jun 10, 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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion sentry-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
24 changes: 12 additions & 12 deletions sentry-core/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand All @@ -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<T: Into<ClientOptions>> From<T> for Client {
Expand Down Expand Up @@ -53,7 +53,7 @@ pub struct Client {
transport: TransportArc,
#[cfg(feature = "release-health")]
session_flusher: RwLock<Option<SessionFlusher>>,
#[cfg(feature = "UNSTABLE_logs")]
#[cfg(feature = "logs")]
logs_batcher: RwLock<Option<LogsBatcher>>,
integrations: Vec<(TypeId, Arc<dyn Integration>)>,
pub(crate) sdk_info: ClientSdkInfo,
Expand All @@ -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 {
Expand All @@ -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(),
Expand Down Expand Up @@ -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 {
Expand All @@ -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,
Expand Down Expand Up @@ -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();
}
Expand All @@ -370,7 +370,7 @@ impl Client {
pub fn close(&self, timeout: Option<Duration>) -> 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 {
Expand All @@ -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;
Expand All @@ -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<Log> {
scope.apply_to_log(&mut log, self.options.send_default_pii);

Expand All @@ -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() {
Expand Down
14 changes: 7 additions & 7 deletions sentry-core/src/clientoptions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -147,7 +147,7 @@ pub struct ClientOptions {
/// Callback that is executed for each Breadcrumb being added.
pub before_breadcrumb: Option<BeforeCallback<Breadcrumb>>,
/// Callback that is executed for each Log being added.
#[cfg(feature = "UNSTABLE_logs")]
#[cfg(feature = "logs")]
pub before_send_log: Option<BeforeCallback<Log>>,
// Transport options
/// The transport to use.
Expand All @@ -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.
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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,
}
}
Expand Down
2 changes: 1 addition & 1 deletion sentry-core/src/hub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
4 changes: 2 additions & 2 deletions sentry-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,15 @@ 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
#[cfg(feature = "client")]
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;
Expand Down
4 changes: 2 additions & 2 deletions sentry-core/src/scope/noop.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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!();
Expand Down
4 changes: 2 additions & 2 deletions sentry-core/src/scope/real.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion sentry/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
10 changes: 5 additions & 5 deletions sentry/tests/test_basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down