Skip to content

Commit 4f8031b

Browse files
committed
unsafe log init
1 parent 2de96cb commit 4f8031b

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

relay-log/src/setup.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,11 @@ fn get_default_filters() -> EnvFilter {
280280

281281
/// Initialize the logging system and reporting to Sentry.
282282
///
283+
/// # Safety
284+
///
285+
/// The function is not safe to be called from a multi-threaded program,
286+
/// due to modifications of environment variables.
287+
///
283288
/// # Example
284289
///
285290
/// ```
@@ -290,9 +295,9 @@ fn get_default_filters() -> EnvFilter {
290295
///
291296
/// let sentry_config = relay_log::SentryConfig::default();
292297
///
293-
/// relay_log::init(&log_config, &sentry_config);
298+
/// unsafe { relay_log::init(&log_config, &sentry_config) };
294299
/// ```
295-
pub fn init(config: &LogConfig, sentry: &SentryConfig) {
300+
pub unsafe fn init(config: &LogConfig, sentry: &SentryConfig) {
296301
if config.enable_backtraces {
297302
unsafe {
298303
env::set_var("RUST_BACKTRACE", "full");

relay/src/cli.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,11 @@ pub fn execute() -> Result<()> {
5252
let env_config = extract_config_env_vars();
5353
config.apply_override(env_config)?;
5454

55-
relay_log::init(config.logging(), config.sentry());
55+
// SAFETY: The function cannot be called from a multi threaded environment,
56+
// this is the main entry point where no other threads have been spawned yet.
57+
unsafe {
58+
relay_log::init(config.logging(), config.sentry());
59+
}
5660

5761
if let Some(matches) = matches.subcommand_matches("config") {
5862
manage_config(&config, matches)

tools/bench-buffer/src/main.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ async fn main() {
5454
duration_secs,
5555
db,
5656
} = args;
57-
relay_log::init(&Default::default(), &Default::default());
57+
unsafe {
58+
relay_log::init(&Default::default(), &Default::default());
59+
}
5860

5961
let dir = tempfile::tempdir().unwrap();
6062
let path = db.unwrap_or(dir.path().join("envelopes.db"));

0 commit comments

Comments
 (0)