@@ -54,6 +54,10 @@ pub(crate) const OTEL_BLRP_MAX_QUEUE_SIZE_DEFAULT: usize = 2_048;
5454pub ( crate ) const OTEL_BLRP_MAX_EXPORT_BATCH_SIZE : & str = "OTEL_BLRP_MAX_EXPORT_BATCH_SIZE" ;
5555/// Default maximum batch size.
5656pub ( crate ) const OTEL_BLRP_MAX_EXPORT_BATCH_SIZE_DEFAULT : usize = 512 ;
57+ /// Force flush timeout
58+ pub ( crate ) const OTEL_BLRP_FORCE_FLUSH_TIMEOUT : & str = "OTEL_BLRP_FORCE_FLUSH_TIMEOUT" ;
59+ /// Default force flush timeout
60+ pub ( crate ) const OTEL_BLRP_FORCE_FLUSH_TIMEOUT_DEFAULT : Duration = Duration :: from_millis ( 5_000 ) ;
5761
5862/// Messages sent between application thread and batch log processor's work thread.
5963#[ allow( clippy:: large_enum_variant) ]
@@ -339,6 +343,7 @@ impl BatchLogProcessor {
339343 let max_export_batch_size = config. max_export_batch_size ;
340344 let current_batch_size = Arc :: new ( AtomicUsize :: new ( 0 ) ) ;
341345 let current_batch_size_for_thread = current_batch_size. clone ( ) ;
346+ let forceflush_timeout = config. forceflush_timeout ;
342347
343348 let handle = thread:: Builder :: new ( )
344349 . name ( "OpenTelemetry.Logs.BatchProcessor" . to_string ( ) )
@@ -489,7 +494,7 @@ impl BatchLogProcessor {
489494 logs_sender,
490495 message_sender,
491496 handle : Mutex :: new ( Some ( handle) ) ,
492- forceflush_timeout : Duration :: from_secs ( 5 ) , // TODO: make this configurable
497+ forceflush_timeout,
493498 dropped_logs_count : AtomicUsize :: new ( 0 ) ,
494499 max_queue_size,
495500 export_log_message_sent : Arc :: new ( AtomicBool :: new ( false ) ) ,
@@ -586,6 +591,9 @@ pub struct BatchConfig {
586591 /// is 512.
587592 pub ( crate ) max_export_batch_size : usize ,
588593
594+ /// The maximum duration to wait when force flushing.
595+ pub ( crate ) forceflush_timeout : Duration ,
596+
589597 /// The maximum duration to export a batch of data.
590598 #[ cfg( feature = "experimental_logs_batch_log_processor_with_async_runtime" ) ]
591599 pub ( crate ) max_export_timeout : Duration ,
@@ -603,6 +611,7 @@ pub struct BatchConfigBuilder {
603611 max_queue_size : usize ,
604612 scheduled_delay : Duration ,
605613 max_export_batch_size : usize ,
614+ forceflush_timeout : Duration ,
606615 #[ cfg( feature = "experimental_logs_batch_log_processor_with_async_runtime" ) ]
607616 max_export_timeout : Duration ,
608617}
@@ -622,6 +631,7 @@ impl Default for BatchConfigBuilder {
622631 max_queue_size : OTEL_BLRP_MAX_QUEUE_SIZE_DEFAULT ,
623632 scheduled_delay : OTEL_BLRP_SCHEDULE_DELAY_DEFAULT ,
624633 max_export_batch_size : OTEL_BLRP_MAX_EXPORT_BATCH_SIZE_DEFAULT ,
634+ forceflush_timeout : OTEL_BLRP_FORCE_FLUSH_TIMEOUT_DEFAULT ,
625635 #[ cfg( feature = "experimental_logs_batch_log_processor_with_async_runtime" ) ]
626636 max_export_timeout : OTEL_BLRP_EXPORT_TIMEOUT_DEFAULT ,
627637 }
@@ -682,6 +692,17 @@ impl BatchConfigBuilder {
682692 self
683693 }
684694
695+ /// Set forceflush_timeout for [`BatchConfigBuilder`].
696+ /// The default value is 5000 milliseconds.
697+ ///
698+ /// Corresponding environment variable: `OTEL_BLRP_FORCE_FLUSH_TIMEOUT`.
699+ ///
700+ /// Note: Programmatically setting this will override any value set via the environment variable.
701+ pub fn with_forceflush_timeout ( mut self , forceflush_timeout : Duration ) -> Self {
702+ self . forceflush_timeout = forceflush_timeout;
703+ self
704+ }
705+
685706 /// Builds a `BatchConfig` enforcing the following invariants:
686707 /// * `max_export_batch_size` must be less than or equal to `max_queue_size`.
687708 pub fn build ( self ) -> BatchConfig {
@@ -692,6 +713,7 @@ impl BatchConfigBuilder {
692713 BatchConfig {
693714 max_queue_size : self . max_queue_size ,
694715 scheduled_delay : self . scheduled_delay ,
716+ forceflush_timeout : self . forceflush_timeout ,
695717 #[ cfg( feature = "experimental_logs_batch_log_processor_with_async_runtime" ) ]
696718 max_export_timeout : self . max_export_timeout ,
697719 max_export_batch_size,
@@ -720,6 +742,13 @@ impl BatchConfigBuilder {
720742 self . scheduled_delay = Duration :: from_millis ( scheduled_delay) ;
721743 }
722744
745+ if let Some ( forceflush_timeout) = env:: var ( OTEL_BLRP_FORCE_FLUSH_TIMEOUT )
746+ . ok ( )
747+ . and_then ( |s| u64:: from_str ( & s) . ok ( ) )
748+ {
749+ self . forceflush_timeout = Duration :: from_millis ( forceflush_timeout) ;
750+ }
751+
723752 #[ cfg( feature = "experimental_logs_batch_log_processor_with_async_runtime" ) ]
724753 if let Some ( max_export_timeout) = env:: var ( OTEL_BLRP_EXPORT_TIMEOUT )
725754 . ok ( )
0 commit comments