Skip to content

Commit 3c68efa

Browse files
committed
more error changes
1 parent 6440a73 commit 3c68efa

File tree

8 files changed

+48
-36
lines changed

8 files changed

+48
-36
lines changed

opentelemetry-otlp/tests/integration_test/tests/logs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ mod logtests {
9494

9595
tokio::time::sleep(Duration::from_secs(10)).await;
9696

97-
assert_logs_results(test_utils::LOGS_FILE, "expected/logs.json");
97+
let _ = assert_logs_results(test_utils::LOGS_FILE, "expected/logs.json");
9898

9999
Ok(())
100100
}
@@ -122,7 +122,7 @@ mod logtests {
122122
}
123123
let _ = logger_provider.shutdown();
124124
// tokio::time::sleep(Duration::from_secs(10)).await;
125-
assert_logs_results(test_utils::LOGS_FILE, "expected/logs.json");
125+
let _ = assert_logs_results(test_utils::LOGS_FILE, "expected/logs.json");
126126

127127
Ok(())
128128
}

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Log exporters
22
use crate::logs::LogRecord;
3-
use crate::logs::{LogError, LogResult, ShutdownError};
3+
use crate::logs::{LogError, ShutdownError};
44
use crate::Resource;
55
use async_trait::async_trait;
66
#[cfg(feature = "spec_unstable_logs_enabled")]
@@ -81,8 +81,10 @@ pub trait LogExporter: Send + Sync + Debug {
8181
/// A `LogResult<()>`, which is a result type indicating either a successful export (with
8282
/// `Ok(())`) or an error (`Err(LogError)`) if the export operation failed.
8383
///
84-
async fn export(&self, batch: LogBatch<'_>) -> LogResult<()>;
85-
/// Shuts down the exporter.
84+
async fn export(&self, batch: LogBatch<'_>) -> ExportResult;
85+
86+
/// Shuts down the exporter. This function is idempotent; calling it
87+
/// more than once has no additional effect.
8688
fn shutdown(&mut self) -> ShutdownResult {
8789
Ok(())
8890
}

opentelemetry-sdk/src/export/trace.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,18 +118,19 @@ pub enum ShutdownError {
118118
#[error("Shutdown timed out after {0:?}")]
119119
Timeout(Duration),
120120

121+
/// The export client failed while holding the client lock. It is not
122+
/// possible to complete the shutdown and a retry will not help.
123+
/// This is something that should not happen and should likely emit some diagnostic.
124+
#[error("export client failed while holding lock; cannot retry.")]
125+
ClientFailed(String),
126+
121127
/// An unexpected error occurred during shutdown.
122128
#[error(transparent)]
123129
Other(#[from] Box<dyn std::error::Error + Send + Sync + 'static>),
124130
}
125131

126-
/// Custom error wrapper for string messages.
127-
#[derive(Error, Debug)]
128-
#[error("{0}")]
129-
struct CustomError(String);
130-
131132
impl<T> From<PoisonError<T>> for ShutdownError {
132133
fn from(err: PoisonError<T>) -> Self {
133-
ShutdownError::Other(Box::new(CustomError(err.to_string())))
134+
ShutdownError::ClientFailed(format!("Mutex poisoned during shutdown: {}", err))
134135
}
135136
}

opentelemetry-sdk/src/logs/error.rs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,16 @@ pub enum LogError {
1818
#[error("Exporter timed out after {} seconds", .0.as_secs())]
1919
ExportTimedOut(Duration),
2020

21+
/// The export client failed while holding the client lock. It is not
22+
/// possible to complete the shutdown and a retry will not help.
23+
/// This is something that should not happen and should likely emit some diagnostic.
24+
#[error("export client failed while holding lock; cannot retry.")]
25+
ClientFailed(String),
26+
2127
/// Processor is already shutdown
2228
#[error("{0} already shutdown")]
2329
AlreadyShutdown(String),
2430

25-
/// Mutex lock poisoning
26-
#[error("mutex lock poisioning for {0}")]
27-
MutexPoisoned(String),
28-
2931
/// Other errors propagated from log SDK that weren't covered above.
3032
#[error(transparent)]
3133
Other(#[from] Box<dyn std::error::Error + Send + Sync + 'static>),
@@ -54,9 +56,10 @@ impl From<&'static str> for LogError {
5456

5557
impl<T> From<PoisonError<T>> for LogError {
5658
fn from(err: PoisonError<T>) -> Self {
57-
LogError::Other(err.to_string().into())
59+
LogError::ClientFailed(err.to_string().into())
5860
}
5961
}
62+
6063
/// Wrap type for string
6164
#[derive(Error, Debug)]
6265
#[error("{0}")]
@@ -66,9 +69,11 @@ struct Custom(String);
6669
#[derive(Error, Debug)]
6770
#[non_exhaustive]
6871
pub enum ShutdownError {
69-
/// Mutex lock poisoning
70-
#[error("mutex lock poisioning for {0}")]
71-
MutexPoisoned(String),
72+
/// The export client failed while holding the client lock. It is not
73+
/// possible to complete the shutdown and a retry will not help.
74+
/// This is something that should not happen and should likely emit some diagnostic.
75+
#[error("export client failed while holding lock; cannot retry.")]
76+
ClientFailed(String),
7277

7378
/// Other errors propagated from log SDK that weren't covered above.
7479
#[error(transparent)]
@@ -77,6 +82,6 @@ pub enum ShutdownError {
7782

7883
impl<T> From<PoisonError<T>> for ShutdownError {
7984
fn from(err: PoisonError<T>) -> Self {
80-
ShutdownError::Other(err.to_string().into())
85+
ShutdownError::ClientFailed(format!("Mutex poisoned during shutdown: {}", err))
8186
}
8287
}

opentelemetry-sdk/src/logs/log_emitter.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,9 @@ impl LoggerProviderInner {
141141
// which is non-actionable by the user
142142
match err {
143143
// specific handling for mutex poisioning
144-
LogError::MutexPoisoned(_) => {
144+
LogError::ClientFailed(_) => {
145145
otel_debug!(
146-
name: "LoggerProvider.Drop.ShutdownMutexPoisoned",
146+
name: "LoggerProvider.Drop.ShutdownClientFailed",
147147
);
148148
}
149149
_ => {

opentelemetry-sdk/src/logs/log_processor.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,14 @@ impl<T: LogExporter> LogProcessor for SimpleLogProcessor<T> {
113113
let result = self
114114
.exporter
115115
.lock()
116-
.map_err(|_| LogError::MutexPoisoned("SimpleLogProcessor".into()))
116+
.map_err(|_| LogError::ClientFailed("SimpleLogProcessor".into()))
117117
.and_then(|exporter| {
118118
let log_tuple = &[(record as &LogRecord, instrumentation)];
119119
futures_executor::block_on(exporter.export(LogBatch::new(log_tuple)))
120120
});
121121
// Handle errors with specific static names
122122
match result {
123-
Err(LogError::MutexPoisoned(_)) => {
123+
Err(LogError::ClientFailed(_)) => {
124124
// logging as debug as this is not a user error
125125
otel_debug!(
126126
name: "SimpleLogProcessor.Emit.MutexPoisoning",
@@ -149,7 +149,8 @@ impl<T: LogExporter> LogProcessor for SimpleLogProcessor<T> {
149149
.map_err(|e| LogError::Other(Box::new(e)))?;
150150
Ok(())
151151
} else {
152-
Err(LogError::MutexPoisoned("SimpleLogProcessor".into()))
152+
// Failing to get the mutex means the export client failed whilst holding it
153+
Err(LogError::ClientFailed("SimpleLogProcessor".into()))
153154
}
154155
}
155156

opentelemetry-sdk/src/testing/logs/in_memory_exporter.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::export::logs::{LogBatch, LogExporter};
1+
use crate::export::logs::{ExportResult, LogBatch, LogExporter};
22
use crate::logs::{LogError, LogResult};
33
use crate::logs::{LogRecord, ShutdownError};
44
use crate::Resource;
@@ -172,19 +172,21 @@ impl InMemoryLogExporter {
172172
/// exporter.reset();
173173
/// ```
174174
///
175-
pub fn reset(&self) {
176-
let _ = self
177-
.logs
178-
.lock()
179-
.map(|mut logs_guard| logs_guard.clear())
180-
.map_err(LogError::from);
175+
pub fn reset(&self) -> Result<(), LogError> {
176+
let _ = self.logs.lock().map(|mut logs_guard| logs_guard.clear())?;
177+
178+
Ok(())
181179
}
182180
}
183181

184182
#[async_trait]
185183
impl LogExporter for InMemoryLogExporter {
186-
async fn export(&self, batch: LogBatch<'_>) -> LogResult<()> {
187-
let mut logs_guard = self.logs.lock().map_err(LogError::from)?;
184+
async fn export(&self, batch: LogBatch<'_>) -> ExportResult {
185+
let mut logs_guard = self
186+
.logs
187+
.lock()
188+
.map_err(|e| LogError::ClientFailed(e.to_string()))?;
189+
188190
for (log_record, instrumentation) in batch.iter() {
189191
let owned_log = OwnedLogData {
190192
record: (*log_record).clone(),
@@ -197,7 +199,8 @@ impl LogExporter for InMemoryLogExporter {
197199

198200
fn shutdown(&mut self) -> Result<(), ShutdownError> {
199201
if self.should_reset_on_shutdown {
200-
self.reset();
202+
self.reset()
203+
.map_err(|e| ShutdownError::Other(Box::new(e)))?;
201204
}
202205
Ok(())
203206
}

opentelemetry-stdout/src/trace/exporter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use chrono::{DateTime, Utc};
22
use core::fmt;
33
use futures_util::future::BoxFuture;
4-
use opentelemetry::trace::{TraceError};
4+
use opentelemetry::trace::TraceError;
55
use opentelemetry_sdk::export::trace::ShutdownResult;
66
use opentelemetry_sdk::export::{self, trace::ExportResult};
77
use opentelemetry_sdk::resource::Resource;

0 commit comments

Comments
 (0)