Skip to content

Commit

Permalink
remove global error handler
Browse files Browse the repository at this point in the history
  • Loading branch information
lalitb committed Oct 28, 2024
1 parent afc8ff5 commit f35e0ec
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 88 deletions.
86 changes: 0 additions & 86 deletions opentelemetry/src/global/error_handler.rs

This file was deleted.

46 changes: 46 additions & 0 deletions opentelemetry/src/global/internal_logging.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
#![allow(unused_macros)]

#[cfg(feature = "logs")]
use crate::logs::LogError;
#[cfg(feature = "metrics")]
use crate::metrics::MetricError;
use crate::propagation::PropagationError;
#[cfg(feature = "trace")]
use crate::trace::TraceError;
use std::sync::PoisonError;

///
/// **Note**: These macros (`otel_info!`, `otel_warn!`, `otel_debug!`, and `otel_error!`) are intended to be used
/// **internally within OpenTelemetry code** or for **custom exporters and processors**. They are not designed
Expand Down Expand Up @@ -156,3 +166,39 @@ macro_rules! otel_error {
}
};
}

/// Wrapper for error from tracing, log, and metrics part of open telemetry.
#[derive(thiserror::Error, Debug)]
#[non_exhaustive]
pub enum Error {
#[cfg(feature = "trace")]
#[cfg_attr(docsrs, doc(cfg(feature = "trace")))]
#[error(transparent)]
/// Failed to export traces.
Trace(#[from] TraceError),
#[cfg(feature = "metrics")]
#[cfg_attr(docsrs, doc(cfg(feature = "metrics")))]
#[error(transparent)]
/// An issue raised by the metrics module.
Metric(#[from] MetricError),

#[cfg(feature = "logs")]
#[cfg_attr(docsrs, doc(cfg(feature = "logs")))]
#[error(transparent)]
/// Failed to export logs.
Log(#[from] LogError),

#[error(transparent)]
/// Error happens when injecting and extracting information using propagators.
Propagation(#[from] PropagationError),

#[error("{0}")]
/// Other types of failures not covered by the variants above.
Other(String),
}

impl<T> From<PoisonError<T>> for Error {
fn from(err: PoisonError<T>) -> Self {
Error::Other(err.to_string())
}
}
3 changes: 1 addition & 2 deletions opentelemetry/src/global/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@
//! [`MeterProvider`]: crate::metrics::MeterProvider
//! [`set_meter_provider`]: crate::global::set_meter_provider
mod error_handler;
mod internal_logging;
#[cfg(feature = "metrics")]
mod metrics;
Expand All @@ -139,7 +138,7 @@ mod propagation;
#[cfg(feature = "trace")]
mod trace;

pub use error_handler::{handle_error, set_error_handler, Error};
pub use internal_logging::Error;
#[cfg(feature = "metrics")]
#[cfg_attr(docsrs, doc(cfg(feature = "metrics")))]
pub use metrics::*;
Expand Down

0 comments on commit f35e0ec

Please sign in to comment.