@@ -3,6 +3,7 @@ use crate::error::{OTelSdkError, OTelSdkResult};
33use crate :: logs:: LogExporter ;
44use crate :: Resource ;
55use opentelemetry:: { otel_debug, otel_info, InstrumentationScope } ;
6+ use std:: time:: Duration ;
67use std:: {
78 borrow:: Cow ,
89 sync:: {
@@ -96,7 +97,7 @@ impl SdkLoggerProvider {
9697 }
9798
9899 /// Shuts down this `LoggerProvider`
99- pub fn shutdown ( & self ) -> OTelSdkResult {
100+ pub fn shutdown_with_timeout ( & self , timeout : Duration ) -> OTelSdkResult {
100101 otel_debug ! (
101102 name: "LoggerProvider.ShutdownInvokedByUser" ,
102103 ) ;
@@ -107,7 +108,7 @@ impl SdkLoggerProvider {
107108 . is_ok ( )
108109 {
109110 // propagate the shutdown signal to processors
110- let result = self . inner . shutdown ( ) ;
111+ let result = self . inner . shutdown_with_timeout ( timeout ) ;
111112 if result. iter ( ) . all ( |res| res. is_ok ( ) ) {
112113 Ok ( ( ) )
113114 } else {
@@ -123,6 +124,11 @@ impl SdkLoggerProvider {
123124 Err ( OTelSdkError :: AlreadyShutdown )
124125 }
125126 }
127+
128+ /// Shuts down this `LoggerProvider` with default timeout
129+ pub fn shutdown ( & self ) -> OTelSdkResult {
130+ self . shutdown_with_timeout ( Duration :: from_secs ( 5 ) )
131+ }
126132}
127133
128134#[ derive( Debug ) ]
@@ -133,10 +139,10 @@ struct LoggerProviderInner {
133139
134140impl LoggerProviderInner {
135141 /// Shuts down the `LoggerProviderInner` and returns any errors.
136- pub ( crate ) fn shutdown ( & self ) -> Vec < OTelSdkResult > {
142+ pub ( crate ) fn shutdown_with_timeout ( & self , timeout : Duration ) -> Vec < OTelSdkResult > {
137143 let mut results = vec ! [ ] ;
138144 for processor in & self . processors {
139- let result = processor. shutdown ( ) ;
145+ let result = processor. shutdown_with_timeout ( timeout ) ;
140146 if let Err ( err) = & result {
141147 // Log at debug level because:
142148 // - The error is also returned to the user for handling (if applicable)
@@ -149,6 +155,11 @@ impl LoggerProviderInner {
149155 }
150156 results
151157 }
158+
159+ /// Shuts down the `LoggerProviderInner` with default timeout and returns any errors.
160+ pub ( crate ) fn shutdown ( & self ) -> Vec < OTelSdkResult > {
161+ self . shutdown_with_timeout ( Duration :: from_secs ( 5 ) )
162+ }
152163}
153164
154165impl Drop for LoggerProviderInner {
@@ -330,7 +341,7 @@ mod tests {
330341 Ok ( ( ) )
331342 }
332343
333- fn shutdown ( & self ) -> OTelSdkResult {
344+ fn shutdown_with_timeout ( & self , _timeout : Duration ) -> OTelSdkResult {
334345 self . is_shutdown
335346 . lock ( )
336347 . map ( |mut is_shutdown| * is_shutdown = true )
@@ -383,10 +394,6 @@ mod tests {
383394 Ok ( ( ) )
384395 }
385396
386- fn shutdown ( & self ) -> OTelSdkResult {
387- Ok ( ( ) )
388- }
389-
390397 fn set_resource ( & mut self , resource : & Resource ) {
391398 let mut res = self . resource . lock ( ) . unwrap ( ) ;
392399 * res = resource. clone ( ) ;
@@ -903,7 +910,7 @@ mod tests {
903910 Ok ( ( ) )
904911 }
905912
906- fn shutdown ( & self ) -> OTelSdkResult {
913+ fn shutdown_with_timeout ( & self , _timeout : Duration ) -> OTelSdkResult {
907914 * self . shutdown_called . lock ( ) . unwrap ( ) = true ;
908915 Ok ( ( ) )
909916 }
@@ -934,7 +941,7 @@ mod tests {
934941 Ok ( ( ) )
935942 }
936943
937- fn shutdown ( & self ) -> OTelSdkResult {
944+ fn shutdown_with_timeout ( & self , _timeout : Duration ) -> OTelSdkResult {
938945 let mut count = self . shutdown_count . lock ( ) . unwrap ( ) ;
939946 * count += 1 ;
940947 Ok ( ( ) )
0 commit comments