@@ -135,53 +135,31 @@ pub trait LogProcessor: Send + Sync + Debug {
135135/// ```
136136#[ derive( Debug ) ]
137137pub struct SimpleLogProcessor < T : LogExporter > {
138- exporter : Mutex < T > ,
139- is_shutdown : AtomicBool ,
138+ exporter : T ,
140139}
141140
142141impl < T : LogExporter > SimpleLogProcessor < T > {
143142 pub ( crate ) fn new ( exporter : T ) -> Self {
144143 SimpleLogProcessor {
145- exporter : Mutex :: new ( exporter) ,
146- is_shutdown : AtomicBool :: new ( false ) ,
144+ exporter : exporter
147145 }
148146 }
149147}
150148
151149impl < T : LogExporter > LogProcessor for SimpleLogProcessor < T > {
152150 fn emit ( & self , record : & mut SdkLogRecord , instrumentation : & InstrumentationScope ) {
153- // noop after shutdown
154- if self . is_shutdown . load ( std:: sync:: atomic:: Ordering :: Relaxed ) {
155- // this is a warning, as the user is trying to log after the processor has been shutdown
156- otel_warn ! (
157- name: "SimpleLogProcessor.Emit.ProcessorShutdown" ,
151+ let log_tuple = & [ ( record as & SdkLogRecord , instrumentation) ] ;
152+ let result = futures_executor:: block_on ( self . exporter . export ( LogBatch :: new ( log_tuple) ) ) ;
153+ if result. is_err ( ) {
154+ otel_error ! (
155+ name: "SimpleLogProcessor.Emit.ExportError" ,
156+ error = format!( "{}" , result. err( ) . unwrap( ) )
158157 ) ;
159- return ;
160158 }
161-
162- let result = self
163- . exporter
164- . lock ( )
165- . map_err ( |_| OTelSdkError :: InternalFailure ( "SimpleLogProcessor mutex poison" . into ( ) ) )
166- . and_then ( |exporter| {
167- let log_tuple = & [ ( record as & SdkLogRecord , instrumentation) ] ;
168- futures_executor:: block_on ( exporter. export ( LogBatch :: new ( log_tuple) ) )
169- } ) ;
170- // Handle errors with specific static names
171- match result {
172- Err ( OTelSdkError :: InternalFailure ( _) ) => {
173- // logging as debug as this is not a user error
174- otel_debug ! (
175- name: "SimpleLogProcessor.Emit.MutexPoisoning" ,
176- ) ;
177- }
178- Err ( err) => {
179- otel_error ! (
180- name: "SimpleLogProcessor.Emit.ExportError" ,
181- error = format!( "{}" , err)
182- ) ;
183- }
184- _ => { }
159+ else {
160+ otel_debug ! (
161+ name: "SimpleLogProcessor.Emit.Success" ,
162+ ) ;
185163 }
186164 }
187165
@@ -190,21 +168,11 @@ impl<T: LogExporter> LogProcessor for SimpleLogProcessor<T> {
190168 }
191169
192170 fn shutdown ( & self ) -> OTelSdkResult {
193- self . is_shutdown
194- . store ( true , std:: sync:: atomic:: Ordering :: Relaxed ) ;
195- if let Ok ( mut exporter) = self . exporter . lock ( ) {
196- exporter. shutdown ( )
197- } else {
198- Err ( OTelSdkError :: InternalFailure (
199- "SimpleLogProcessor mutex poison at shutdown" . into ( ) ,
200- ) )
201- }
171+ self . exporter . shutdown ( )
202172 }
203173
204174 fn set_resource ( & self , resource : & Resource ) {
205- if let Ok ( mut exporter) = self . exporter . lock ( ) {
206- exporter. set_resource ( resource) ;
207- }
175+ self . exporter . set_resource ( resource) ;
208176 }
209177}
210178
@@ -481,7 +449,7 @@ impl LogProcessor for BatchLogProcessor {
481449}
482450
483451impl BatchLogProcessor {
484- pub ( crate ) fn new < E > ( mut exporter : E , config : BatchConfig ) -> Self
452+ pub ( crate ) fn new < E > ( exporter : E , config : BatchConfig ) -> Self
485453 where
486454 E : LogExporter + Send + Sync + ' static ,
487455 {
@@ -909,11 +877,11 @@ mod tests {
909877 async { Ok ( ( ) ) }
910878 }
911879
912- fn shutdown ( & mut self ) -> OTelSdkResult {
880+ fn shutdown ( & self ) -> OTelSdkResult {
913881 Ok ( ( ) )
914882 }
915883
916- fn set_resource ( & mut self , resource : & Resource ) {
884+ fn set_resource ( & self , resource : & Resource ) {
917885 self . resource
918886 . lock ( )
919887 . map ( |mut res_opt| {
@@ -1171,17 +1139,14 @@ mod tests {
11711139 let instrumentation: InstrumentationScope = Default :: default ( ) ;
11721140
11731141 processor. emit ( & mut record, & instrumentation) ;
1174-
11751142 processor. shutdown ( ) . unwrap ( ) ;
11761143
1177- let is_shutdown = processor
1178- . is_shutdown
1179- . load ( std:: sync:: atomic:: Ordering :: Relaxed ) ;
1180- assert ! ( is_shutdown) ;
1181-
1144+ // Emit after shutdown.
11821145 processor. emit ( & mut record, & instrumentation) ;
11831146
1184- assert_eq ! ( 1 , exporter. get_emitted_logs( ) . unwrap( ) . len( ) )
1147+ // SimpleProcessor does not do anything to check if logs
1148+ // are flowing after shutdown.
1149+ assert_eq ! ( 2 , exporter. get_emitted_logs( ) . unwrap( ) . len( ) )
11851150 }
11861151
11871152 #[ tokio:: test( flavor = "current_thread" ) ]
0 commit comments