@@ -85,7 +85,11 @@ pub trait SpanProcessor: Send + Sync + std::fmt::Debug {
8585 /// TODO - This method should take reference to `SpanData`
8686 fn on_end ( & self , span : SpanData ) ;
8787 /// Force the spans lying in the cache to be exported.
88- fn force_flush ( & self ) -> OTelSdkResult ;
88+ fn force_flush_with_timeout ( & self , _timeout : Duration ) -> OTelSdkResult ;
89+ /// Force flush the spans with a default timeout.
90+ fn force_flush ( & self ) -> OTelSdkResult {
91+ self . force_flush_with_timeout ( Duration :: from_secs ( 5 ) )
92+ }
8993 /// Shuts down the processor. Called when SDK is shut down. This is an
9094 /// opportunity for processors to do any cleanup required.
9195 ///
@@ -153,7 +157,7 @@ impl<T: SpanExporter> SpanProcessor for SimpleSpanProcessor<T> {
153157 }
154158 }
155159
156- fn force_flush ( & self ) -> OTelSdkResult {
160+ fn force_flush_with_timeout ( & self , _timeout : Duration ) -> OTelSdkResult {
157161 // Nothing to flush for simple span processor.
158162 Ok ( ( ) )
159163 }
@@ -286,7 +290,6 @@ pub struct BatchSpanProcessor {
286290 span_sender : SyncSender < SpanData > , // Data channel to store spans
287291 message_sender : SyncSender < BatchMessage > , // Control channel to store control messages.
288292 handle : Mutex < Option < thread:: JoinHandle < ( ) > > > ,
289- forceflush_timeout : Duration ,
290293 export_span_message_sent : Arc < AtomicBool > ,
291294 current_batch_size : Arc < AtomicUsize > ,
292295 max_export_batch_size : usize ,
@@ -424,7 +427,6 @@ impl BatchSpanProcessor {
424427 span_sender,
425428 message_sender,
426429 handle : Mutex :: new ( Some ( handle) ) ,
427- forceflush_timeout : Duration :: from_secs ( 5 ) , // TODO: make this configurable
428430 dropped_spans_count : AtomicUsize :: new ( 0 ) ,
429431 max_queue_size,
430432 export_span_message_sent : Arc :: new ( AtomicBool :: new ( false ) ) ,
@@ -593,21 +595,19 @@ impl SpanProcessor for BatchSpanProcessor {
593595 }
594596
595597 /// Flushes all pending spans.
596- fn force_flush ( & self ) -> OTelSdkResult {
598+ fn force_flush_with_timeout ( & self , timeout : Duration ) -> OTelSdkResult {
597599 let ( sender, receiver) = std:: sync:: mpsc:: sync_channel ( 1 ) ;
598600 match self
599601 . message_sender
600602 . try_send ( BatchMessage :: ForceFlush ( sender) )
601603 {
602- Ok ( _) => receiver
603- . recv_timeout ( self . forceflush_timeout )
604- . map_err ( |err| {
605- if err == std:: sync:: mpsc:: RecvTimeoutError :: Timeout {
606- OTelSdkError :: Timeout ( self . forceflush_timeout )
607- } else {
608- OTelSdkError :: InternalFailure ( format ! ( "{err}" ) )
609- }
610- } ) ?,
604+ Ok ( _) => receiver. recv_timeout ( timeout) . map_err ( |err| {
605+ if err == std:: sync:: mpsc:: RecvTimeoutError :: Timeout {
606+ OTelSdkError :: Timeout ( timeout)
607+ } else {
608+ OTelSdkError :: InternalFailure ( format ! ( "{err}" ) )
609+ }
610+ } ) ?,
611611 Err ( std:: sync:: mpsc:: TrySendError :: Full ( _) ) => {
612612 // If the control message could not be sent, emit a warning.
613613 otel_debug ! (
0 commit comments