-
Notifications
You must be signed in to change notification settings - Fork 437
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
148 additions
and
150 deletions.
There are no files selected for viewing
5 changes: 2 additions & 3 deletions
5
opentelemetry/src/global/error_handler.rs → opentelemetry-sdk/src/error.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -148,3 +148,5 @@ pub mod util; | |
|
||
#[doc(inline)] | ||
pub use resource::Resource; | ||
|
||
pub mod error; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
use crate::export::ExportError; | ||
|
||
use std::{sync::PoisonError, time::Duration}; | ||
use thiserror::Error; | ||
|
||
/// Describe the result of operations in log SDK. | ||
pub type LogResult<T> = Result<T, LogError>; | ||
|
||
#[derive(Error, Debug)] | ||
#[non_exhaustive] | ||
/// Errors returned by the log SDK. | ||
pub enum LogError { | ||
/// Export failed with the error returned by the exporter. | ||
#[error("Exporter {} encountered the following errors: {0}", .0.exporter_name())] | ||
ExportFailed(Box<dyn ExportError>), | ||
|
||
/// Export failed to finish after certain period and processor stopped the export. | ||
#[error("Exporter timed out after {} seconds", .0.as_secs())] | ||
ExportTimedOut(Duration), | ||
|
||
/// Processor is already shutdown | ||
#[error("{0} already shutdown")] | ||
AlreadyShutdown(String), | ||
|
||
/// Mutex lock poisoning | ||
#[error("mutex lock poisioning for {0}")] | ||
MutexPoisoned(String), | ||
|
||
/// Other errors propagated from log SDK that weren't covered above. | ||
#[error(transparent)] | ||
Other(#[from] Box<dyn std::error::Error + Send + Sync + 'static>), | ||
} | ||
|
||
impl<T> From<T> for LogError | ||
where | ||
T: ExportError, | ||
{ | ||
fn from(err: T) -> Self { | ||
LogError::ExportFailed(Box::new(err)) | ||
} | ||
} | ||
|
||
impl From<String> for LogError { | ||
fn from(err_msg: String) -> Self { | ||
LogError::Other(Box::new(Custom(err_msg))) | ||
} | ||
} | ||
|
||
impl From<&'static str> for LogError { | ||
fn from(err_msg: &'static str) -> Self { | ||
LogError::Other(Box::new(Custom(err_msg.into()))) | ||
} | ||
} | ||
|
||
impl<T> From<PoisonError<T>> for LogError { | ||
fn from(err: PoisonError<T>) -> Self { | ||
LogError::Other(err.to_string().into()) | ||
} | ||
} | ||
/// Wrap type for string | ||
#[derive(Error, Debug)] | ||
#[error("{0}")] | ||
struct Custom(String); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
use std::result; | ||
use std::sync::PoisonError; | ||
use thiserror::Error; | ||
|
||
use crate::export::ExportError; | ||
|
||
/// A specialized `Result` type for metric operations. | ||
pub type MetricResult<T> = result::Result<T, MetricError>; | ||
|
||
/// Errors returned by the metrics API. | ||
#[derive(Error, Debug)] | ||
#[non_exhaustive] | ||
pub enum MetricError { | ||
/// Other errors not covered by specific cases. | ||
#[error("Metrics error: {0}")] | ||
Other(String), | ||
/// Invalid configuration | ||
#[error("Config error {0}")] | ||
Config(String), | ||
/// Fail to export metrics | ||
#[error("Metrics exporter {} failed with {0}", .0.exporter_name())] | ||
ExportErr(Box<dyn ExportError>), | ||
/// Invalid instrument configuration such invalid instrument name, invalid instrument description, invalid instrument unit, etc. | ||
/// See [spec](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/api.md#general-characteristics) | ||
/// for full list of requirements. | ||
#[error("Invalid instrument configuration: {0}")] | ||
InvalidInstrumentConfiguration(&'static str), | ||
} | ||
|
||
impl<T: ExportError> From<T> for MetricError { | ||
fn from(err: T) -> Self { | ||
MetricError::ExportErr(Box::new(err)) | ||
} | ||
} | ||
|
||
impl<T> From<PoisonError<T>> for MetricError { | ||
fn from(err: PoisonError<T>) -> Self { | ||
MetricError::Other(err.to_string()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.