@@ -12,9 +12,8 @@ use futures_util::{
12
12
#[ cfg( feature = "logs_level_enabled" ) ]
13
13
use opentelemetry:: logs:: Severity ;
14
14
use opentelemetry:: {
15
- global,
16
15
logs:: { LogError , LogResult } ,
17
- otel_error, otel_warn, InstrumentationLibrary ,
16
+ otel_debug , otel_error, otel_warn, InstrumentationLibrary ,
18
17
} ;
19
18
20
19
use std:: sync:: atomic:: AtomicBool ;
@@ -99,26 +98,36 @@ impl LogProcessor for SimpleLogProcessor {
99
98
fn emit ( & self , record : & mut LogRecord , instrumentation : & InstrumentationLibrary ) {
100
99
// noop after shutdown
101
100
if self . is_shutdown . load ( std:: sync:: atomic:: Ordering :: Relaxed ) {
101
+ // this is a warning, as the user is trying to log after the processor has been shutdown
102
102
otel_warn ! (
103
- name: "simple_log_processor_emit_after_shutdown"
103
+ name: "SimpleLogProcessor.Emit.ProcessorShutdown" ,
104
104
) ;
105
105
return ;
106
106
}
107
107
108
108
let result = self
109
109
. exporter
110
110
. lock ( )
111
- . map_err ( |_| LogError :: Other ( "simple logprocessor mutex poison ". into ( ) ) )
111
+ . map_err ( |_| LogError :: MutexPoisoned ( "SimpleLogProcessor ". into ( ) ) )
112
112
. and_then ( |mut exporter| {
113
113
let log_tuple = & [ ( record as & LogRecord , instrumentation) ] ;
114
114
futures_executor:: block_on ( exporter. export ( LogBatch :: new ( log_tuple) ) )
115
115
} ) ;
116
- if let Err ( err) = result {
117
- otel_error ! (
118
- name: "simple_log_processor_emit_error" ,
119
- error = format!( "{:?}" , err)
120
- ) ;
121
- global:: handle_error ( err) ;
116
+ // Handle errors with specific static names
117
+ match result {
118
+ Err ( LogError :: MutexPoisoned ( _) ) => {
119
+ // logging as debug as this is not a user error
120
+ otel_debug ! (
121
+ name: "SimpleLogProcessor.Emit.MutexPoisoning" ,
122
+ ) ;
123
+ }
124
+ Err ( err) => {
125
+ otel_error ! (
126
+ name: "SimpleLogProcessor.Emit.ExportError" ,
127
+ error = format!( "{}" , err)
128
+ ) ;
129
+ }
130
+ _ => { }
122
131
}
123
132
}
124
133
@@ -133,12 +142,7 @@ impl LogProcessor for SimpleLogProcessor {
133
142
exporter. shutdown ( ) ;
134
143
Ok ( ( ) )
135
144
} else {
136
- otel_error ! (
137
- name: "simple_log_processor_shutdown_error"
138
- ) ;
139
- Err ( LogError :: Other (
140
- "simple logprocessor mutex poison during shutdown" . into ( ) ,
141
- ) )
145
+ Err ( LogError :: MutexPoisoned ( "SimpleLogProcessor" . into ( ) ) )
142
146
}
143
147
}
144
148
@@ -170,12 +174,12 @@ impl<R: RuntimeChannel> LogProcessor for BatchLogProcessor<R> {
170
174
instrumentation. clone ( ) ,
171
175
) ) ) ;
172
176
177
+ // TODO - Implement throttling to prevent error flooding when the queue is full or closed.
173
178
if let Err ( err) = result {
174
179
otel_error ! (
175
- name: "batch_log_processor_emit_error " ,
176
- error = format!( "{:? }" , err)
180
+ name: "BatchLogProcessor.Export.Error " ,
181
+ error = format!( "{}" , err)
177
182
) ;
178
- global:: handle_error ( LogError :: Other ( err. into ( ) ) ) ;
179
183
}
180
184
}
181
185
@@ -243,10 +247,9 @@ impl<R: RuntimeChannel> BatchLogProcessor<R> {
243
247
244
248
if let Err ( err) = result {
245
249
otel_error ! (
246
- name: "batch_log_processor_export_error " ,
247
- error = format!( "{:? }" , err)
250
+ name: "BatchLogProcessor.Export.Error " ,
251
+ error = format!( "{}" , err)
248
252
) ;
249
- global:: handle_error ( err) ;
250
253
}
251
254
}
252
255
}
@@ -261,24 +264,12 @@ impl<R: RuntimeChannel> BatchLogProcessor<R> {
261
264
. await ;
262
265
263
266
if let Some ( channel) = res_channel {
264
- if let Err ( result) = channel. send ( result) {
265
- global:: handle_error ( LogError :: from ( format ! (
266
- "failed to send flush result: {:?}" ,
267
- result
268
- ) ) ) ;
269
- otel_error ! (
270
- name: "batch_log_processor_flush_error" ,
271
- error = format!( "{:?}" , result) ,
272
- message = "Failed to send flush result"
267
+ if let Err ( send_error) = channel. send ( result) {
268
+ otel_debug ! (
269
+ name: "BatchLogProcessor.Flush.SendResultError" ,
270
+ error = format!( "{:?}" , send_error) ,
273
271
) ;
274
272
}
275
- } else if let Err ( err) = result {
276
- otel_error ! (
277
- name: "batch_log_processor_flush_error" ,
278
- error = format!( "{:?}" , err) ,
279
- message = "Flush failed"
280
- ) ;
281
- global:: handle_error ( err) ;
282
273
}
283
274
}
284
275
// Stream has terminated or processor is shutdown, return to finish execution.
@@ -293,21 +284,14 @@ impl<R: RuntimeChannel> BatchLogProcessor<R> {
293
284
294
285
exporter. shutdown ( ) ;
295
286
296
- if let Err ( result) = ch. send ( result) {
297
- otel_error ! (
298
- name: "batch_log_processor_shutdown_error" ,
299
- error = format!( "{:?}" , result) ,
300
- message = "Failed to send shutdown result"
287
+ if let Err ( send_error) = ch. send ( result) {
288
+ otel_debug ! (
289
+ name: "BatchLogProcessor.Shutdown.SendResultError" ,
290
+ error = format!( "{:?}" , send_error) ,
301
291
) ;
302
- global:: handle_error ( LogError :: from ( format ! (
303
- "failed to send batch processor shutdown result: {:?}" ,
304
- result
305
- ) ) ) ;
306
292
}
307
-
308
293
break ;
309
294
}
310
-
311
295
// propagate the resource
312
296
BatchMessage :: SetResource ( resource) => {
313
297
exporter. set_resource ( & resource) ;
@@ -357,13 +341,7 @@ where
357
341
pin_mut ! ( timeout) ;
358
342
match future:: select ( export, timeout) . await {
359
343
Either :: Left ( ( export_res, _) ) => export_res,
360
- Either :: Right ( ( _, _) ) => {
361
- otel_error ! (
362
- name: "export_with_timeout_timeout" ,
363
- timeout_duration = time_out. as_millis( )
364
- ) ;
365
- ExportResult :: Err ( LogError :: ExportTimedOut ( time_out) )
366
- }
344
+ Either :: Right ( ( _, _) ) => ExportResult :: Err ( LogError :: ExportTimedOut ( time_out) ) ,
367
345
}
368
346
}
369
347
0 commit comments