|
1 | 1 | #![allow(unused_macros)] |
| 2 | + |
| 3 | +#[cfg(feature = "logs")] |
| 4 | +use crate::logs::LogError; |
| 5 | +#[cfg(feature = "metrics")] |
| 6 | +use crate::metrics::MetricError; |
| 7 | +use crate::propagation::PropagationError; |
| 8 | +#[cfg(feature = "trace")] |
| 9 | +use crate::trace::TraceError; |
| 10 | +use std::sync::PoisonError; |
| 11 | + |
2 | 12 | /// |
3 | 13 | /// **Note**: These macros (`otel_info!`, `otel_warn!`, `otel_debug!`, and `otel_error!`) are intended to be used |
4 | 14 | /// **internally within OpenTelemetry code** or for **custom exporters and processors**. They are not designed |
@@ -156,3 +166,39 @@ macro_rules! otel_error { |
156 | 166 | } |
157 | 167 | }; |
158 | 168 | } |
| 169 | + |
| 170 | +/// Wrapper for error from tracing, log, and metrics part of open telemetry. |
| 171 | +#[derive(thiserror::Error, Debug)] |
| 172 | +#[non_exhaustive] |
| 173 | +pub enum Error { |
| 174 | + #[cfg(feature = "trace")] |
| 175 | + #[cfg_attr(docsrs, doc(cfg(feature = "trace")))] |
| 176 | + #[error(transparent)] |
| 177 | + /// Failed to export traces. |
| 178 | + Trace(#[from] TraceError), |
| 179 | + #[cfg(feature = "metrics")] |
| 180 | + #[cfg_attr(docsrs, doc(cfg(feature = "metrics")))] |
| 181 | + #[error(transparent)] |
| 182 | + /// An issue raised by the metrics module. |
| 183 | + Metric(#[from] MetricError), |
| 184 | + |
| 185 | + #[cfg(feature = "logs")] |
| 186 | + #[cfg_attr(docsrs, doc(cfg(feature = "logs")))] |
| 187 | + #[error(transparent)] |
| 188 | + /// Failed to export logs. |
| 189 | + Log(#[from] LogError), |
| 190 | + |
| 191 | + #[error(transparent)] |
| 192 | + /// Error happens when injecting and extracting information using propagators. |
| 193 | + Propagation(#[from] PropagationError), |
| 194 | + |
| 195 | + #[error("{0}")] |
| 196 | + /// Other types of failures not covered by the variants above. |
| 197 | + Other(String), |
| 198 | +} |
| 199 | + |
| 200 | +impl<T> From<PoisonError<T>> for Error { |
| 201 | + fn from(err: PoisonError<T>) -> Self { |
| 202 | + Error::Other(err.to_string()) |
| 203 | + } |
| 204 | +} |
0 commit comments