Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: modify LogExporter and TraceExporter interfaces to support returning failure #2381

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
4 changes: 0 additions & 4 deletions opentelemetry-sdk/src/export/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,6 @@ pub struct SpanData {
#[derive(Error, Debug)]
#[non_exhaustive]
pub enum ShutdownError {
/// The exporter has already been shut down.
#[error("Shutdown already performed")]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed this as discussed

AlreadyShutdown,

/// Shutdown timed out before completing.
#[error("Shutdown timed out after {0:?}")]
Timeout(Duration),
Expand Down
6 changes: 0 additions & 6 deletions opentelemetry-sdk/src/logs/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,6 @@ impl From<&'static str> for LogError {
}
}

impl<T> From<PoisonError<T>> for LogError {
fn from(err: PoisonError<T>) -> Self {
LogError::ClientFailed(err.to_string())
}
}

/// Wrap type for string
#[derive(Error, Debug)]
#[error("{0}")]
Expand Down
21 changes: 17 additions & 4 deletions opentelemetry-sdk/src/testing/logs/in_memory_exporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,17 @@ impl InMemoryLogExporter {
/// ```
///
pub fn get_emitted_logs(&self) -> LogResult<Vec<LogDataWithResource>> {
let logs_guard = self.logs.lock().map_err(LogError::from)?;
let resource_guard = self.resource.lock().map_err(LogError::from)?;
let logs_guard = self.logs.lock().map_err(|_| {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The mutex poisoned errors here are an implementation detail of InMemoryLogExporter - that is, they have nothing to do with the common shape of a LogExporter.

So, I removed the automatic From for poisoned on the LogError type and explicitly map detailed errors through here.

LogError::from(
"InMemoryLogExporter: log buffer mutex poisoned trying to get_emitted_logs",
)
})?;
let resource_guard = self.resource.lock().map_err(|_| {
LogError::from(
"InMemoryLogExporter: resource mutex poisoned trying to get_emitted_logs",
)
})?;

let logs: Vec<LogDataWithResource> = logs_guard
.iter()
.map(|log_data| LogDataWithResource {
Expand All @@ -173,8 +182,12 @@ impl InMemoryLogExporter {
/// ```
///
pub fn reset(&self) -> Result<(), LogError> {
self.logs.lock().map(|mut logs_guard| logs_guard.clear())?;

self.logs
.lock()
.map_err(|_| {
LogError::from("InMemoryLogExporter: log buffer mutex poisoned trying to reset()")
})
.map(|mut logs_guard| logs_guard.clear())?;
Ok(())
}
}
Expand Down