11//! Wrapper for error from trace, logs and metrics part of open telemetry.
2- use std:: sync:: PoisonError ;
3-
42#[ cfg( feature = "logs" ) ]
53use crate :: logs:: LogError ;
64#[ cfg( feature = "metrics" ) ]
75use crate :: metrics:: MetricError ;
86use opentelemetry:: propagation:: PropagationError ;
97#[ cfg( feature = "trace" ) ]
108use opentelemetry:: trace:: TraceError ;
9+ use std:: sync:: PoisonError ;
10+ use std:: time:: Duration ;
11+ use thiserror:: Error ;
1112
12- /// Wrapper for error from both tracing and metrics part of open telemetry.
13+ /// Wrapper for error from both tracing and metrics part of open telemetry. This
14+ /// gives us a common error type where we _need_ to return errors that may come
15+ /// from various components.
1316#[ derive( thiserror:: Error , Debug ) ]
1417#[ non_exhaustive]
1518pub enum Error {
@@ -34,6 +37,10 @@ pub enum Error {
3437 /// Error happens when injecting and extracting information using propagators.
3538 Propagation ( #[ from] PropagationError ) ,
3639
40+ /// Failed to shutdown an exporter
41+ #[ error( transparent) ]
42+ Shutdown ( #[ from] ShutdownError ) ,
43+
3744 #[ error( "{0}" ) ]
3845 /// Other types of failures not covered by the variants above.
3946 Other ( String ) ,
@@ -44,3 +51,28 @@ impl<T> From<PoisonError<T>> for Error {
4451 Error :: Other ( err. to_string ( ) )
4552 }
4653}
54+
55+ /// Errors returned by shutdown operations in the Export API.
56+ #[ derive( Error , Debug ) ]
57+ #[ non_exhaustive]
58+ pub enum ShutdownError {
59+ /// Shutdown timed out before completing.
60+ #[ error( "Shutdown timed out after {0:?}" ) ]
61+ Timeout ( Duration ) ,
62+
63+ /// The export client failed while holding the client lock. It is not
64+ /// possible to complete the shutdown and a retry will not help.
65+ /// This is something that should not happen and should likely emit some diagnostic.
66+ #[ error( "export client failed while holding lock; cannot retry." ) ]
67+ ClientFailed ( String ) ,
68+
69+ /// An unexpected error occurred during shutdown.
70+ #[ error( transparent) ]
71+ Other ( #[ from] Box < dyn std:: error:: Error + Send + Sync + ' static > ) ,
72+ }
73+
74+ impl < T > From < PoisonError < T > > for ShutdownError {
75+ fn from ( err : PoisonError < T > ) -> Self {
76+ ShutdownError :: ClientFailed ( format ! ( "Mutex poisoned during shutdown: {}" , err) )
77+ }
78+ }
0 commit comments