@@ -5,15 +5,15 @@ use opentelemetry::trace::{SpanContext, SpanId, SpanKind, Status, TraceError};
55use opentelemetry:: { InstrumentationScope , KeyValue } ;
66use std:: borrow:: Cow ;
77use std:: fmt:: Debug ;
8- use std:: time:: SystemTime ;
8+ use std:: sync:: PoisonError ;
9+ use std:: time:: { Duration , SystemTime } ;
10+ use thiserror:: Error ;
911
10- /// Describes the results of other operations on the trace API.
11- pub type TraceResult < T > = Result < T , TraceError > ;
12+ /// Results of an export operation
13+ pub type ExportResult = Result < ( ) , TraceError > ;
1214
13- /// Describes the results of an export
14- /// Note: This is an alias we will remove in the future, favouring
15- /// using TraceResult directly.
16- pub type ExportResult = TraceResult < ( ) > ;
15+ /// Result of a shutdown operation
16+ pub type ShutdownResult = Result < ( ) , ShutdownError > ;
1717
1818/// `SpanExporter` defines the interface that protocol-specific exporters must
1919/// implement so that they can be plugged into OpenTelemetry SDK and support
@@ -35,7 +35,7 @@ pub trait SpanExporter: Send + Sync + Debug {
3535 ///
3636 /// Any retry logic that is required by the exporter is the responsibility
3737 /// of the exporter.
38- fn export ( & mut self , batch : Vec < SpanData > ) -> BoxFuture < ' static , TraceResult < ( ) > > ;
38+ fn export ( & mut self , batch : Vec < SpanData > ) -> BoxFuture < ' static , Result < ( ) , TraceError > > ;
3939
4040 /// Shuts down the exporter. Called when SDK is shut down. This is an
4141 /// opportunity for exporter to do any cleanup required.
@@ -48,7 +48,7 @@ pub trait SpanExporter: Send + Sync + Debug {
4848 /// flush the data and the destination is unavailable). SDK authors
4949 /// can decide if they want to make the shutdown timeout
5050 /// configurable.
51- fn shutdown ( & mut self ) -> TraceResult < ( ) > {
51+ fn shutdown ( & mut self ) -> ShutdownResult {
5252 Ok ( ( ) )
5353 }
5454
@@ -105,3 +105,31 @@ pub struct SpanData {
105105 /// Instrumentation scope that produced this span
106106 pub instrumentation_scope : InstrumentationScope ,
107107}
108+
109+ /// Errors returned by shutdown operations in the Export API.
110+ #[ derive( Error , Debug ) ]
111+ #[ non_exhaustive]
112+ pub enum ShutdownError {
113+ /// The exporter has already been shut down.
114+ #[ error( "Shutdown already performed" ) ]
115+ AlreadyShutdown ,
116+
117+ /// Shutdown timed out before completing.
118+ #[ error( "Shutdown timed out after {0:?}" ) ]
119+ Timeout ( Duration ) ,
120+
121+ /// An unexpected error occurred during shutdown.
122+ #[ error( transparent) ]
123+ Other ( #[ from] Box < dyn std:: error:: Error + Send + Sync + ' static > ) ,
124+ }
125+
126+ /// Custom error wrapper for string messages.
127+ #[ derive( Error , Debug ) ]
128+ #[ error( "{0}" ) ]
129+ struct CustomError ( String ) ;
130+
131+ impl < T > From < PoisonError < T > > for ShutdownError {
132+ fn from ( err : PoisonError < T > ) -> Self {
133+ ShutdownError :: Other ( Box :: new ( CustomError ( err. to_string ( ) ) ) )
134+ }
135+ }
0 commit comments