opentelemetry_sdk/
error.rs

1//! Wrapper for error from trace, logs and metrics part of open telemetry.
2
3use std::{result::Result, time::Duration};
4
5use thiserror::Error;
6
7/// Trait for errors returned by exporters
8pub trait ExportError: std::error::Error + Send + Sync + 'static {
9    /// The name of exporter that returned this error
10    fn exporter_name(&self) -> &'static str;
11}
12
13#[derive(Error, Debug)]
14/// Errors that can occur during SDK operations export(), force_flush() and shutdown().
15pub enum OTelSdkError {
16    /// Shutdown has already been invoked.
17    ///
18    /// While shutdown is idempotent and calling it multiple times has no
19    /// impact, this error suggests that another part of the application is
20    /// invoking `shutdown` earlier than intended. Users should review their
21    /// code to identify unintended or duplicate shutdown calls and ensure it is
22    /// only triggered once at the correct place.
23    #[error("Shutdown already invoked")]
24    AlreadyShutdown,
25
26    /// Operation timed out before completing.
27    ///
28    /// This does not necessarily indicate a failure—operation may still be
29    /// complete. If this occurs frequently, consider increasing the timeout
30    /// duration to allow more time for completion.
31    #[error("Operation timed out after {0:?}")]
32    Timeout(Duration),
33
34    /// Operation failed due to an internal error.
35    ///
36    /// The error message is intended for logging purposes only and should not
37    /// be used to make programmatic decisions. It is implementation-specific
38    /// and subject to change without notice. Consumers of this error should not
39    /// rely on its content beyond logging.
40    #[error("Operation failed: {0}")]
41    InternalFailure(String),
42}
43
44/// A specialized `Result` type for Shutdown operations.
45pub type OTelSdkResult = Result<(), OTelSdkError>;