Skip to content

Commit 3d34774

Browse files
more logical rewrite with just replacing the macro on feature flag
1 parent 1a152f7 commit 3d34774

File tree

14 files changed

+13
-35
lines changed

14 files changed

+13
-35
lines changed

sentry-core/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ name = "scope_benchmark"
2020
harness = false
2121

2222
[features]
23-
default = ["debug_logs"]
23+
default = []
2424
client = ["rand"]
2525
test = ["client", "release-health"]
2626
debug_logs = []

sentry-core/src/client.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,6 @@ impl Client {
282282
event = match integration.process_event(event, &self.options) {
283283
Some(event) => event,
284284
None => {
285-
#[cfg(feature = "debug_logs")]
286285
sentry_debug!("integration dropped event {:?}", id);
287286
return None;
288287
}
@@ -303,13 +302,11 @@ impl Client {
303302
}
304303

305304
if let Some(ref func) = self.options.before_send {
306-
#[cfg(feature = "debug_logs")]
307305
sentry_debug!("invoking before_send callback");
308306
let id = event.event_id;
309307
if let Some(processed_event) = func(event) {
310308
event = processed_event;
311309
} else {
312-
#[cfg(feature = "debug_logs")]
313310
sentry_debug!("before_send dropped event {:?}", id);
314311
return None;
315312
}
@@ -444,11 +441,9 @@ impl Client {
444441
drop(self.logs_batcher.write().unwrap().take());
445442
let transport_opt = self.transport.write().unwrap().take();
446443
if let Some(transport) = transport_opt {
447-
#[cfg(feature = "debug_logs")]
448444
sentry_debug!("client close; request transport to shut down");
449445
transport.shutdown(timeout.unwrap_or(self.options.shutdown_timeout))
450446
} else {
451-
#[cfg(feature = "debug_logs")]
452447
sentry_debug!("client close; no transport to shut down");
453448
true
454449
}
@@ -470,7 +465,6 @@ impl Client {
470465
#[cfg(feature = "logs")]
471466
pub fn capture_log(&self, log: Log, scope: &Scope) {
472467
if !self.options.enable_logs {
473-
#[cfg(feature = "debug_logs")]
474468
sentry_debug!("[Client] called capture_log, but options.enable_logs is set to false");
475469
return;
476470
}

sentry-core/src/logs.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ impl LogsBatcher {
104104
return;
105105
}
106106

107-
#[cfg(feature = "debug_logs")]
108107
sentry_debug!("[LogsBatcher] Flushing {} logs", logs.len());
109108
if let Some(ref transport) = *transport.read().unwrap() {
110109
let mut envelope = Envelope::new();

sentry-core/src/macros.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ macro_rules! with_client_impl {
5353
// TODO: temporarily exported for use in `sentry` crate
5454
#[macro_export]
5555
#[doc(hidden)]
56+
#[cfg(feature = "debug_logs")]
5657
macro_rules! sentry_debug {
5758
($($arg:tt)*) => {
5859
$crate::Hub::with(|hub| {
@@ -64,6 +65,16 @@ macro_rules! sentry_debug {
6465
}
6566
}
6667

68+
/// Replace the exported macro with a no-op macro when debug_logs is disabled.
69+
#[macro_export]
70+
#[doc(hidden)]
71+
#[cfg(not(feature = "debug_logs"))]
72+
macro_rules! sentry_debug {
73+
($($arg:tt)*) => {
74+
();
75+
};
76+
}
77+
6778
#[allow(unused_macros)]
6879
macro_rules! minimal_unreachable {
6980
() => {

sentry-core/src/scope/real.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,6 @@ impl Scope {
318318
event = match processor(event) {
319319
Some(event) => event,
320320
None => {
321-
#[cfg(feature = "debug_logs")]
322321
sentry_debug!("event processor dropped event {}", id);
323322
return None;
324323
}

sentry-core/src/session.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,6 @@ mod session_impl {
294294
bucket.abnormal += 1;
295295
}
296296
SessionStatus::Ok => {
297-
#[cfg(feature = "debug_logs")]
298297
sentry_debug!("unreachable: only closed sessions will be enqueued");
299298
}
300299
}

sentry/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ opentelemetry = ["sentry-opentelemetry"]
4949
test = ["sentry-core/test"]
5050
release-health = ["sentry-core/release-health", "sentry-actix?/release-health"]
5151
logs = ["sentry-core/logs", "sentry-tracing?/logs", "sentry-log?/logs"]
52+
debug_logs = ["sentry-core/debug_logs"]
5253
# transports
5354
transport = ["reqwest", "native-tls"]
5455
reqwest = ["dep:reqwest", "httpdate", "tokio"]

sentry/src/init.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,8 @@ impl ClientInitGuard {
3131
impl Drop for ClientInitGuard {
3232
fn drop(&mut self) {
3333
if self.is_enabled() {
34-
#[cfg(feature = "debug_logs")]
3534
sentry_debug!("dropping client guard -> disposing client");
3635
} else {
37-
#[cfg(feature = "debug_logs")]
3836
sentry_debug!("dropping client guard (no client to dispose)");
3937
}
4038
// end any session that might be open before closing the client
@@ -108,10 +106,8 @@ where
108106

109107
Hub::with(|hub| hub.bind_client(Some(client.clone())));
110108
if let Some(dsn) = client.dsn() {
111-
#[cfg(feature = "debug_logs")]
112109
sentry_debug!("enabled sentry client for DSN {}", dsn);
113110
} else {
114-
#[cfg(feature = "debug_logs")]
115111
sentry_debug!("initialized disabled sentry client due to disabled or invalid DSN");
116112
}
117113
#[cfg(feature = "release-health")]

sentry/src/transports/curl.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,11 @@ impl CurlHttpTransport {
5151
match (scheme, &http_proxy, &https_proxy) {
5252
(Scheme::Https, _, Some(proxy)) => {
5353
if let Err(err) = handle.proxy(proxy) {
54-
#[cfg(feature = "debug_logs")]
5554
sentry_debug!("invalid proxy: {:?}", err);
5655
}
5756
}
5857
(_, Some(proxy), _) => {
5958
if let Err(err) = handle.proxy(proxy) {
60-
#[cfg(feature = "debug_logs")]
6159
sentry_debug!("invalid proxy: {:?}", err);
6260
}
6361
}
@@ -88,7 +86,6 @@ impl CurlHttpTransport {
8886
curl::easy::InfoType::DataOut => "",
8987
_ => return,
9088
};
91-
#[cfg(feature = "debug_logs")]
9289
sentry_debug!("curl: {}{}", prefix, String::from_utf8_lossy(data).trim());
9390
})
9491
.unwrap();
@@ -127,7 +124,6 @@ impl CurlHttpTransport {
127124
}
128125
}
129126
Err(err) => {
130-
#[cfg(feature = "debug_logs")]
131127
sentry_debug!("Failed to send envelope: {}", err);
132128
}
133129
}

sentry/src/transports/embedded_svc_http.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ impl EmbeddedSVCHttpTransport {
5858
impl Transport for EmbeddedSVCHttpTransport {
5959
fn send_envelope(&self, envelope: sentry_core::Envelope) {
6060
if let Err(err) = self.send_envelope(envelope) {
61-
#[cfg(feature = "debug_logs")]
6261
sentry_debug!("Failed to send envelope: {}", err);
6362
}
6463
}

0 commit comments

Comments
 (0)