Skip to content

Commit 26bbdc4

Browse files
committed
Re-export ShutdownError from common location
1 parent 4df322f commit 26bbdc4

File tree

5 files changed

+48
-57
lines changed

5 files changed

+48
-57
lines changed

examples/tracing-grpc/src/server.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ use opentelemetry::{
55
propagation::Extractor,
66
trace::{Span, SpanKind, Tracer},
77
};
8-
use opentelemetry_sdk::{
9-
propagation::TraceContextPropagator, trace::TracerProvider,
10-
};
8+
use opentelemetry_sdk::{propagation::TraceContextPropagator, trace::TracerProvider};
119
use opentelemetry_stdout::SpanExporter;
1210
use tonic::{transport::Server, Request, Response, Status};
1311

opentelemetry-sdk/src/error.rs

+35-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
//! Wrapper for error from trace, logs and metrics part of open telemetry.
2-
use std::sync::PoisonError;
3-
42
#[cfg(feature = "logs")]
53
use crate::logs::LogError;
64
#[cfg(feature = "metrics")]
75
use crate::metrics::MetricError;
86
use opentelemetry::propagation::PropagationError;
97
#[cfg(feature = "trace")]
108
use 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]
1518
pub 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+
}

opentelemetry-sdk/src/export/logs/mod.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
//! Log exporters
2+
use crate::logs::LogError;
23
use crate::logs::LogRecord;
3-
use crate::logs::{LogError, ShutdownError};
44
use crate::Resource;
55
#[cfg(feature = "spec_unstable_logs_enabled")]
66
use opentelemetry::logs::Severity;
77
use opentelemetry::InstrumentationScope;
88
use std::fmt::Debug;
99

10+
// Re-export ShutdownError
11+
pub use crate::error::ShutdownError;
12+
1013
/// A batch of log records to be exported by a `LogExporter`.
1114
///
1215
/// The `LogBatch` struct holds a collection of log records along with their associated

opentelemetry-sdk/src/export/trace.rs

+4-28
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ use opentelemetry::trace::{SpanContext, SpanId, SpanKind, Status, TraceError};
55
use opentelemetry::{InstrumentationScope, KeyValue};
66
use std::borrow::Cow;
77
use std::fmt::Debug;
8-
use std::sync::PoisonError;
9-
use std::time::{Duration, SystemTime};
10-
use thiserror::Error;
8+
use std::time::SystemTime;
9+
10+
// Re-export ShutdownError
11+
pub use crate::error::ShutdownError;
1112

1213
/// Results of an export operation
1314
pub type ExportResult = Result<(), TraceError>;
@@ -105,28 +106,3 @@ pub struct SpanData {
105106
/// Instrumentation scope that produced this span
106107
pub instrumentation_scope: InstrumentationScope,
107108
}
108-
109-
/// Errors returned by shutdown operations in the Export API.
110-
#[derive(Error, Debug)]
111-
#[non_exhaustive]
112-
pub enum ShutdownError {
113-
/// Shutdown timed out before completing.
114-
#[error("Shutdown timed out after {0:?}")]
115-
Timeout(Duration),
116-
117-
/// The export client failed while holding the client lock. It is not
118-
/// possible to complete the shutdown and a retry will not help.
119-
/// This is something that should not happen and should likely emit some diagnostic.
120-
#[error("export client failed while holding lock; cannot retry.")]
121-
ClientFailed(String),
122-
123-
/// An unexpected error occurred during shutdown.
124-
#[error(transparent)]
125-
Other(#[from] Box<dyn std::error::Error + Send + Sync + 'static>),
126-
}
127-
128-
impl<T> From<PoisonError<T>> for ShutdownError {
129-
fn from(err: PoisonError<T>) -> Self {
130-
ShutdownError::ClientFailed(format!("Mutex poisoned during shutdown: {}", err))
131-
}
132-
}

opentelemetry-sdk/src/logs/error.rs

+4-22
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
// Re-export ShutdownError
2+
pub use crate::error::ShutdownError;
3+
14
use crate::export::ExportError;
25

3-
use std::{sync::PoisonError, time::Duration};
6+
use std::time::Duration;
47
use thiserror::Error;
58

69
/// Describe the result of operations in log SDK.
@@ -58,24 +61,3 @@ impl From<&'static str> for LogError {
5861
#[derive(Error, Debug)]
5962
#[error("{0}")]
6063
struct Custom(String);
61-
62-
/// Errors returned during shutdown
63-
#[derive(Error, Debug)]
64-
#[non_exhaustive]
65-
pub enum ShutdownError {
66-
/// The export client failed while holding the client lock. It is not
67-
/// possible to complete the shutdown and a retry will not help.
68-
/// This is something that should not happen and should likely emit some diagnostic.
69-
#[error("export client failed while holding lock; cannot retry.")]
70-
ClientFailed(String),
71-
72-
/// Other errors propagated from log SDK that weren't covered above.
73-
#[error(transparent)]
74-
Other(#[from] Box<dyn std::error::Error + Send + Sync + 'static>),
75-
}
76-
77-
impl<T> From<PoisonError<T>> for ShutdownError {
78-
fn from(err: PoisonError<T>) -> Self {
79-
ShutdownError::ClientFailed(format!("Mutex poisoned during shutdown: {}", err))
80-
}
81-
}

0 commit comments

Comments
 (0)