Skip to content

Commit bc598d0

Browse files
authored
fix(setup): Log when reporting to Sentry is disabled (#779)
The logging integration of Sentry SDK 0.19 and 0.20 supresses log messages when the client is disabled, for instance if the DSN is set to None. Since this is the default configuration of Relay, logs no longer print to standard error by default. This PR skips initializing the Sentry SDK if error reporting is disabled and instead registers the logger directly.
1 parent 9722aa8 commit bc598d0

File tree

1 file changed

+34
-29
lines changed

1 file changed

+34
-29
lines changed

relay/src/setup.rs

+34-29
Original file line numberDiff line numberDiff line change
@@ -165,35 +165,40 @@ pub fn init_logging(config: &Config) {
165165

166166
let log = Box::new(log_builder.build());
167167

168-
let log_integration = sentry::integrations::log::LogIntegration {
169-
global_filter: Some(log.filter()),
170-
attach_stacktraces: config.enable_backtraces(),
171-
dest_log: Some(log),
172-
..Default::default()
173-
};
174-
175-
let guard = sentry::init(sentry::ClientOptions {
176-
dsn: config
177-
.sentry_dsn()
178-
.map(|dsn| dsn.to_string().parse().unwrap()),
179-
in_app_include: vec![
180-
"relay_auth::",
181-
"relay_common::",
182-
"relay_config::",
183-
"relay_filter::",
184-
"relay_general::",
185-
"relay_quotas::",
186-
"relay_redis::",
187-
"relay_server::",
188-
"relay::",
189-
],
190-
release: sentry::release_name!(),
191-
integrations: vec![Arc::new(log_integration)],
192-
..Default::default()
193-
});
194-
195-
// Keep the client initialized. The client is flushed manually in `main`.
196-
mem::forget(guard);
168+
if let Some(dsn) = config.sentry_dsn() {
169+
let log_integration = sentry::integrations::log::LogIntegration {
170+
global_filter: Some(log.filter()),
171+
attach_stacktraces: config.enable_backtraces(),
172+
dest_log: Some(log),
173+
..Default::default()
174+
};
175+
176+
let guard = sentry::init(sentry::ClientOptions {
177+
dsn: Some(dsn.to_string().parse().unwrap()),
178+
in_app_include: vec![
179+
"relay_auth::",
180+
"relay_common::",
181+
"relay_config::",
182+
"relay_filter::",
183+
"relay_general::",
184+
"relay_quotas::",
185+
"relay_redis::",
186+
"relay_server::",
187+
"relay::",
188+
],
189+
release: sentry::release_name!(),
190+
integrations: vec![Arc::new(log_integration)],
191+
..Default::default()
192+
});
193+
194+
// Keep the client initialized. The client is flushed manually in `main`.
195+
mem::forget(guard);
196+
} else {
197+
// Work around a bug in the Sentry 0.20.1 log integration that suppresses logs when Sentry
198+
// is disabled. Instead, register the plain logger and skip initializing Sentry.
199+
log::set_max_level(log.filter());
200+
log::set_boxed_logger(log).ok();
201+
}
197202
}
198203

199204
/// Initialize the metric system.

0 commit comments

Comments
 (0)