File tree Expand file tree Collapse file tree 3 files changed +15
-4
lines changed Expand file tree Collapse file tree 3 files changed +15
-4
lines changed Original file line number Diff line number Diff line change @@ -280,6 +280,11 @@ fn get_default_filters() -> EnvFilter {
280
280
281
281
/// Initialize the logging system and reporting to Sentry.
282
282
///
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
+ ///
283
288
/// # Example
284
289
///
285
290
/// ```
@@ -290,9 +295,9 @@ fn get_default_filters() -> EnvFilter {
290
295
///
291
296
/// let sentry_config = relay_log::SentryConfig::default();
292
297
///
293
- /// relay_log::init(&log_config, &sentry_config);
298
+ /// unsafe { relay_log::init(&log_config, &sentry_config) } ;
294
299
/// ```
295
- pub fn init ( config : & LogConfig , sentry : & SentryConfig ) {
300
+ pub unsafe fn init ( config : & LogConfig , sentry : & SentryConfig ) {
296
301
if config. enable_backtraces {
297
302
unsafe {
298
303
env:: set_var ( "RUST_BACKTRACE" , "full" ) ;
Original file line number Diff line number Diff line change @@ -52,7 +52,11 @@ pub fn execute() -> Result<()> {
52
52
let env_config = extract_config_env_vars ( ) ;
53
53
config. apply_override ( env_config) ?;
54
54
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
+ }
56
60
57
61
if let Some ( matches) = matches. subcommand_matches ( "config" ) {
58
62
manage_config ( & config, matches)
Original file line number Diff line number Diff line change @@ -54,7 +54,9 @@ async fn main() {
54
54
duration_secs,
55
55
db,
56
56
} = args;
57
- relay_log:: init ( & Default :: default ( ) , & Default :: default ( ) ) ;
57
+ unsafe {
58
+ relay_log:: init ( & Default :: default ( ) , & Default :: default ( ) ) ;
59
+ }
58
60
59
61
let dir = tempfile:: tempdir ( ) . unwrap ( ) ;
60
62
let path = db. unwrap_or ( dir. path ( ) . join ( "envelopes.db" ) ) ;
You can’t perform that action at this time.
0 commit comments