opentelemetry_sdk/trace/
error.rs

1use crate::ExportError;
2use std::sync::PoisonError;
3use std::time;
4use thiserror::Error;
5
6/// A specialized `Result` type for trace operations.
7pub type TraceResult<T> = Result<T, TraceError>;
8
9/// Errors returned by the trace API.
10#[derive(Error, Debug)]
11#[non_exhaustive]
12pub enum TraceError {
13    /// Export failed with the error returned by the exporter
14    #[error("Exporter {0} encountered the following error(s): {name}", name = .0.exporter_name())]
15    ExportFailed(Box<dyn ExportError>),
16
17    /// Export failed to finish after certain period and processor stopped the export.
18    #[error("Exporting timed out after {} seconds", .0.as_secs())]
19    ExportTimedOut(time::Duration),
20
21    /// already shutdown error
22    #[error("TracerProvider already shutdown")]
23    TracerProviderAlreadyShutdown,
24
25    /// Other errors propagated from trace SDK that weren't covered above
26    #[error(transparent)]
27    Other(#[from] Box<dyn std::error::Error + Send + Sync + 'static>),
28}
29
30impl<T> From<T> for TraceError
31where
32    T: ExportError,
33{
34    fn from(err: T) -> Self {
35        TraceError::ExportFailed(Box::new(err))
36    }
37}
38
39impl From<String> for TraceError {
40    fn from(err_msg: String) -> Self {
41        TraceError::Other(err_msg.into())
42    }
43}
44
45impl From<&'static str> for TraceError {
46    fn from(err_msg: &'static str) -> Self {
47        TraceError::Other(Box::new(Custom(err_msg.into())))
48    }
49}
50
51impl<T> From<PoisonError<T>> for TraceError {
52    fn from(err: PoisonError<T>) -> Self {
53        TraceError::Other(err.to_string().into())
54    }
55}
56
57/// Wrap type for string
58#[derive(Error, Debug)]
59#[error("{0}")]
60struct Custom(String);