@@ -26,7 +26,7 @@ use crate::{
26
26
use opentelemetry:: { otel_warn, InstrumentationScope } ;
27
27
28
28
use std:: fmt:: Debug ;
29
- use std:: sync:: atomic :: { AtomicBool , Ordering } ;
29
+ use std:: sync:: Mutex ;
30
30
31
31
/// A [`LogProcessor`] designed for testing and debugging purpose, that immediately
32
32
/// exports log records as they are emitted. Log records are exported synchronously
@@ -60,15 +60,15 @@ use std::sync::atomic::{AtomicBool, Ordering};
60
60
#[ derive( Debug ) ]
61
61
pub struct SimpleLogProcessor < T : LogExporter > {
62
62
exporter : T ,
63
- is_exporting : AtomicBool ,
63
+ export_mutex : Mutex < ( ) > ,
64
64
}
65
65
66
66
impl < T : LogExporter > SimpleLogProcessor < T > {
67
67
/// Creates a new instance of `SimpleLogProcessor`.
68
68
pub fn new ( exporter : T ) -> Self {
69
69
SimpleLogProcessor {
70
70
exporter,
71
- is_exporting : AtomicBool :: new ( false ) ,
71
+ export_mutex : Mutex :: new ( ( ) ) ,
72
72
}
73
73
}
74
74
}
@@ -78,23 +78,13 @@ impl<T: LogExporter> LogProcessor for SimpleLogProcessor<T> {
78
78
// export() does not require mutable self and can be called in parallel
79
79
// with other export() calls. However, OTel Spec requires that
80
80
// existing export() must be completed before the next export() call.
81
- while !self
82
- . is_exporting
83
- . compare_exchange ( false , true , Ordering :: Acquire , Ordering :: Relaxed )
84
- . is_ok ( )
85
- {
86
- // Another thread is currently exporting, yield to let other work proceed
87
- std:: thread:: yield_now ( ) ;
88
- }
81
+ let _guard = self . export_mutex . lock ( ) . unwrap ( ) ;
89
82
90
83
// We now have exclusive access to export
91
84
let result = {
92
85
let log_tuple = & [ ( record as & SdkLogRecord , instrumentation) ] ;
93
86
futures_executor:: block_on ( self . exporter . export ( LogBatch :: new ( log_tuple) ) )
94
87
} ;
95
-
96
- // Release the lock
97
- self . is_exporting . store ( false , Ordering :: Release ) ;
98
88
if let Err ( err) = result {
99
89
otel_warn ! (
100
90
name: "SimpleLogProcessor.Emit.ExportError" ,
0 commit comments