Skip to content

Commit 1a152f7

Browse files
simple debug_logs flag to cfg on/off sentry_debug!
1 parent a57b91c commit 1a152f7

File tree

13 files changed

+39
-2
lines changed

13 files changed

+39
-2
lines changed

sentry-core/Cargo.toml

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

2222
[features]
23-
default = []
23+
default = ["debug_logs"]
2424
client = ["rand"]
2525
test = ["client", "release-health"]
26+
debug_logs = []
2627
release-health = []
2728
logs = []
2829

sentry-core/src/client.rs

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

304305
if let Some(ref func) = self.options.before_send {
306+
#[cfg(feature = "debug_logs")]
305307
sentry_debug!("invoking before_send callback");
306308
let id = event.event_id;
307309
if let Some(processed_event) = func(event) {
308310
event = processed_event;
309311
} else {
312+
#[cfg(feature = "debug_logs")]
310313
sentry_debug!("before_send dropped event {:?}", id);
311314
return None;
312315
}
@@ -441,9 +444,11 @@ impl Client {
441444
drop(self.logs_batcher.write().unwrap().take());
442445
let transport_opt = self.transport.write().unwrap().take();
443446
if let Some(transport) = transport_opt {
447+
#[cfg(feature = "debug_logs")]
444448
sentry_debug!("client close; request transport to shut down");
445449
transport.shutdown(timeout.unwrap_or(self.options.shutdown_timeout))
446450
} else {
451+
#[cfg(feature = "debug_logs")]
447452
sentry_debug!("client close; no transport to shut down");
448453
true
449454
}
@@ -465,6 +470,7 @@ impl Client {
465470
#[cfg(feature = "logs")]
466471
pub fn capture_log(&self, log: Log, scope: &Scope) {
467472
if !self.options.enable_logs {
473+
#[cfg(feature = "debug_logs")]
468474
sentry_debug!("[Client] called capture_log, but options.enable_logs is set to false");
469475
return;
470476
}

sentry-core/src/logs.rs

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

107+
#[cfg(feature = "debug_logs")]
107108
sentry_debug!("[LogsBatcher] Flushing {} logs", logs.len());
108-
109109
if let Some(ref transport) = *transport.read().unwrap() {
110110
let mut envelope = Envelope::new();
111111
let logs_item: EnvelopeItem = logs.into();

sentry-core/src/scope/real.rs

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

sentry-core/src/session.rs

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

sentry-log/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@
5454
//!
5555
//! let logger = sentry_log::SentryLogger::new().filter(|md| match md.level() {
5656
//! log::Level::Error => LogFilter::Event,
57+
//! #[cfg(feature = "logs")]
5758
//! log::Level::Warn => LogFilter::Breadcrumb | LogFilter::Log,
59+
//! #[cfg(not(feature = "logs"))]
60+
//! log::Level::Warn => LogFilter::Breadcrumb,
5861
//! _ => LogFilter::Ignore,
5962
//! });
6063
//! ```

sentry/src/init.rs

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

107109
Hub::with(|hub| hub.bind_client(Some(client.clone())));
108110
if let Some(dsn) = client.dsn() {
111+
#[cfg(feature = "debug_logs")]
109112
sentry_debug!("enabled sentry client for DSN {}", dsn);
110113
} else {
114+
#[cfg(feature = "debug_logs")]
111115
sentry_debug!("initialized disabled sentry client due to disabled or invalid DSN");
112116
}
113117
#[cfg(feature = "release-health")]

sentry/src/transports/curl.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,13 @@ 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")]
5455
sentry_debug!("invalid proxy: {:?}", err);
5556
}
5657
}
5758
(_, Some(proxy), _) => {
5859
if let Err(err) = handle.proxy(proxy) {
60+
#[cfg(feature = "debug_logs")]
5961
sentry_debug!("invalid proxy: {:?}", err);
6062
}
6163
}
@@ -86,6 +88,7 @@ impl CurlHttpTransport {
8688
curl::easy::InfoType::DataOut => "",
8789
_ => return,
8890
};
91+
#[cfg(feature = "debug_logs")]
8992
sentry_debug!("curl: {}{}", prefix, String::from_utf8_lossy(data).trim());
9093
})
9194
.unwrap();
@@ -124,6 +127,7 @@ impl CurlHttpTransport {
124127
}
125128
}
126129
Err(err) => {
130+
#[cfg(feature = "debug_logs")]
127131
sentry_debug!("Failed to send envelope: {}", err);
128132
}
129133
}

sentry/src/transports/embedded_svc_http.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ 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")]
6162
sentry_debug!("Failed to send envelope: {}", err);
6263
}
6364
}

sentry/src/transports/reqwest.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ impl ReqwestHttpTransport {
3939
builder = builder.proxy(proxy);
4040
}
4141
Err(err) => {
42+
#[cfg(feature = "debug_logs")]
4243
sentry_debug!("invalid proxy: {:?}", err);
4344
}
4445
}
@@ -49,6 +50,7 @@ impl ReqwestHttpTransport {
4950
builder = builder.proxy(proxy);
5051
}
5152
Err(err) => {
53+
#[cfg(feature = "debug_logs")]
5254
sentry_debug!("invalid proxy: {:?}", err);
5355
}
5456
}
@@ -90,14 +92,17 @@ impl ReqwestHttpTransport {
9092

9193
match response.text().await {
9294
Err(err) => {
95+
#[cfg(feature = "debug_logs")]
9396
sentry_debug!("Failed to read sentry response: {}", err);
9497
}
9598
Ok(text) => {
99+
#[cfg(feature = "debug_logs")]
96100
sentry_debug!("Get response: `{}`", text);
97101
}
98102
}
99103
}
100104
Err(err) => {
105+
#[cfg(feature = "debug_logs")]
101106
sentry_debug!("Failed to send envelope: {}", err);
102107
}
103108
}

0 commit comments

Comments
 (0)