1
1
//! Wrapper for error from trace, logs and metrics part of open telemetry.
2
- use std:: sync:: PoisonError ;
3
-
4
2
#[ cfg( feature = "logs" ) ]
5
3
use crate :: logs:: LogError ;
6
4
#[ cfg( feature = "metrics" ) ]
7
5
use crate :: metrics:: MetricError ;
8
6
use opentelemetry:: propagation:: PropagationError ;
9
7
#[ cfg( feature = "trace" ) ]
10
8
use opentelemetry:: trace:: TraceError ;
9
+ use std:: sync:: PoisonError ;
10
+ use std:: time:: Duration ;
11
+ use thiserror:: Error ;
11
12
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.
13
16
#[ derive( thiserror:: Error , Debug ) ]
14
17
#[ non_exhaustive]
15
18
pub enum Error {
@@ -34,6 +37,10 @@ pub enum Error {
34
37
/// Error happens when injecting and extracting information using propagators.
35
38
Propagation ( #[ from] PropagationError ) ,
36
39
40
+ /// Failed to shutdown an exporter
41
+ #[ error( transparent) ]
42
+ Shutdown ( #[ from] ShutdownError ) ,
43
+
37
44
#[ error( "{0}" ) ]
38
45
/// Other types of failures not covered by the variants above.
39
46
Other ( String ) ,
@@ -44,3 +51,28 @@ impl<T> From<PoisonError<T>> for Error {
44
51
Error :: Other ( err. to_string ( ) )
45
52
}
46
53
}
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