@@ -199,7 +199,7 @@ impl<T: LogExporter> LogProcessor for SimpleLogProcessor<T> {
199
199
#[ allow( clippy:: large_enum_variant) ]
200
200
#[ derive( Debug ) ]
201
201
enum BatchMessage {
202
- /// This ONLY sent when the number of logs records in the data channel has reached `max_export_batch_size`.
202
+ /// This is ONLY sent when the number of logs records in the data channel has reached `max_export_batch_size`.
203
203
ExportLog ( Arc < AtomicBool > ) ,
204
204
/// ForceFlush flushes the current buffer to the exporter.
205
205
ForceFlush ( mpsc:: SyncSender < ExportResult > ) ,
@@ -457,23 +457,31 @@ impl BatchLogProcessor {
457
457
where
458
458
E : LogExporter + Send + Sync + ' static ,
459
459
{
460
- // Get upto `max_export_batch_size` amount of logs log records from the channel and push them to the logs vec
461
- while let Ok ( log) = logs_receiver. try_recv ( ) {
462
- logs. push ( log) ;
463
- if logs. len ( ) == config. max_export_batch_size {
464
- break ;
460
+ let target = current_batch_size. load ( Ordering :: Relaxed ) ; // `target` is used to determine the stopping criteria for exporting logs.
461
+ let mut result = LogResult :: Ok ( ( ) ) ;
462
+ let mut total_exported_logs: usize = 0 ;
463
+
464
+ while target > 0 && total_exported_logs < target {
465
+ // Get upto `max_export_batch_size` amount of logs log records from the channel and push them to the logs vec
466
+ while let Ok ( log) = logs_receiver. try_recv ( ) {
467
+ logs. push ( log) ;
468
+ if logs. len ( ) == config. max_export_batch_size {
469
+ break ;
470
+ }
465
471
}
466
- }
467
472
468
- let count_of_logs = logs. len ( ) ; // Count of logs that will be exported
469
- let result = export_with_timeout_sync (
470
- config. max_export_timeout ,
471
- exporter,
472
- logs,
473
- last_export_time,
474
- ) ; // This method clears the logs vec after exporting
473
+ let count_of_logs = logs. len ( ) ; // Count of logs that will be exported
474
+ total_exported_logs += count_of_logs;
475
+
476
+ result = export_with_timeout_sync (
477
+ config. max_export_timeout ,
478
+ exporter,
479
+ logs,
480
+ last_export_time,
481
+ ) ; // This method clears the logs vec after exporting
475
482
476
- current_batch_size. fetch_sub ( count_of_logs, Ordering :: Relaxed ) ;
483
+ current_batch_size. fetch_sub ( count_of_logs, Ordering :: Relaxed ) ;
484
+ }
477
485
result
478
486
}
479
487
@@ -485,6 +493,9 @@ impl BatchLogProcessor {
485
493
486
494
match message_receiver. recv_timeout ( remaining_time) {
487
495
Ok ( BatchMessage :: ExportLog ( export_log_message_sent) ) => {
496
+ // Reset the export log message sent flag now it has has been processed.
497
+ export_log_message_sent. store ( false , Ordering :: Relaxed ) ;
498
+
488
499
otel_debug ! (
489
500
name: "BatchLogProcessor.ExportingDueToBatchSize" ,
490
501
) ;
@@ -497,9 +508,6 @@ impl BatchLogProcessor {
497
508
& current_batch_size,
498
509
& config,
499
510
) ;
500
-
501
- // Reset the export log message sent flag now it has has been processed.
502
- export_log_message_sent. store ( false , Ordering :: Relaxed ) ;
503
511
}
504
512
Ok ( BatchMessage :: ForceFlush ( sender) ) => {
505
513
otel_debug ! ( name: "BatchLogProcessor.ExportingDueToForceFlush" ) ;
0 commit comments