Skip to content

Commit 9cf5898

Browse files
committed
initial commit
1 parent a4381ce commit 9cf5898

File tree

25 files changed

+148
-150
lines changed

25 files changed

+148
-150
lines changed

opentelemetry/src/global/error_handler.rs renamed to opentelemetry-sdk/src/error.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
use std::sync::PoisonError;
2-
use std::sync::RwLock;
32

43
#[cfg(feature = "logs")]
54
use crate::logs::LogError;
65
#[cfg(feature = "metrics")]
76
use crate::metrics::MetricError;
8-
use crate::propagation::PropagationError;
7+
use opentelemetry::propagation::PropagationError;
98
#[cfg(feature = "trace")]
10-
use crate::trace::TraceError;
9+
use opentelemetry::trace::TraceError;
1110

1211
/// Wrapper for error from both tracing and metrics part of open telemetry.
1312
#[derive(thiserror::Error, Debug)]

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
//! Log exporters
22
use crate::logs::LogRecord;
3+
use crate::logs::{LogError, LogResult};
34
use crate::Resource;
45
use async_trait::async_trait;
56
#[cfg(feature = "logs_level_enabled")]
67
use opentelemetry::logs::Severity;
7-
use opentelemetry::logs::{LogError, LogResult};
88
use opentelemetry::InstrumentationScope;
99
use std::fmt::Debug;
1010

opentelemetry-sdk/src/export/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,8 @@ pub mod logs;
88
#[cfg_attr(docsrs, doc(cfg(feature = "trace")))]
99
pub mod trace;
1010

11-
pub use opentelemetry::ExportError;
11+
/// Marker trait for errors returned by exporters
12+
pub trait ExportError: std::error::Error + Send + Sync + 'static {
13+
/// The name of exporter that returned this error
14+
fn exporter_name(&self) -> &'static str;
15+
}

opentelemetry-sdk/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,3 +148,5 @@ pub mod util;
148148

149149
#[doc(inline)]
150150
pub use resource::Resource;
151+
152+
pub mod error;
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
use crate::export::ExportError;
2+
3+
use std::{sync::PoisonError, time::Duration};
4+
use thiserror::Error;
5+
6+
/// Describe the result of operations in log SDK.
7+
pub type LogResult<T> = Result<T, LogError>;
8+
9+
#[derive(Error, Debug)]
10+
#[non_exhaustive]
11+
/// Errors returned by the log SDK.
12+
pub enum LogError {
13+
/// Export failed with the error returned by the exporter.
14+
#[error("Exporter {} encountered the following errors: {0}", .0.exporter_name())]
15+
ExportFailed(Box<dyn ExportError>),
16+
17+
/// Export failed to finish after certain period and processor stopped the export.
18+
#[error("Exporter timed out after {} seconds", .0.as_secs())]
19+
ExportTimedOut(Duration),
20+
21+
/// Processor is already shutdown
22+
#[error("{0} already shutdown")]
23+
AlreadyShutdown(String),
24+
25+
/// Mutex lock poisoning
26+
#[error("mutex lock poisioning for {0}")]
27+
MutexPoisoned(String),
28+
29+
/// Other errors propagated from log SDK that weren't covered above.
30+
#[error(transparent)]
31+
Other(#[from] Box<dyn std::error::Error + Send + Sync + 'static>),
32+
}
33+
34+
impl<T> From<T> for LogError
35+
where
36+
T: ExportError,
37+
{
38+
fn from(err: T) -> Self {
39+
LogError::ExportFailed(Box::new(err))
40+
}
41+
}
42+
43+
impl From<String> for LogError {
44+
fn from(err_msg: String) -> Self {
45+
LogError::Other(Box::new(Custom(err_msg)))
46+
}
47+
}
48+
49+
impl From<&'static str> for LogError {
50+
fn from(err_msg: &'static str) -> Self {
51+
LogError::Other(Box::new(Custom(err_msg.into())))
52+
}
53+
}
54+
55+
impl<T> From<PoisonError<T>> for LogError {
56+
fn from(err: PoisonError<T>) -> Self {
57+
LogError::Other(err.to_string().into())
58+
}
59+
}
60+
/// Wrap type for string
61+
#[derive(Error, Debug)]
62+
#[error("{0}")]
63+
struct Custom(String);

opentelemetry-sdk/src/logs/log_emitter.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
use super::{BatchLogProcessor, LogProcessor, LogRecord, SimpleLogProcessor, TraceContext};
22
use crate::{export::logs::LogExporter, runtime::RuntimeChannel, Resource};
3-
use opentelemetry::{
4-
logs::{LogError, LogResult},
5-
otel_debug,
6-
trace::TraceContextExt,
7-
Context, InstrumentationScope,
8-
};
3+
use crate::{logs::LogError, logs::LogResult};
4+
use opentelemetry::{otel_debug, trace::TraceContextExt, Context, InstrumentationScope};
95

106
#[cfg(feature = "logs_level_enabled")]
117
use opentelemetry::logs::Severity;

opentelemetry-sdk/src/logs/log_processor.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::{
22
export::logs::{ExportResult, LogBatch, LogExporter},
3-
logs::LogRecord,
3+
logs::{LogError, LogRecord, LogResult},
44
runtime::{RuntimeChannel, TrySend},
55
Resource,
66
};
@@ -11,10 +11,7 @@ use futures_util::{
1111
};
1212
#[cfg(feature = "logs_level_enabled")]
1313
use opentelemetry::logs::Severity;
14-
use opentelemetry::{
15-
logs::{LogError, LogResult},
16-
otel_debug, otel_error, otel_warn, InstrumentationScope,
17-
};
14+
use opentelemetry::{otel_debug, otel_error, otel_warn, InstrumentationScope};
1815

1916
use std::sync::atomic::AtomicBool;
2017
use std::{cmp::min, env, sync::Mutex};

opentelemetry-sdk/src/logs/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
//! # OpenTelemetry Log SDK
2+
mod error;
23
mod log_emitter;
34
mod log_processor;
45
pub(crate) mod record;
56

7+
pub use error::{LogError, LogResult};
68
pub use log_emitter::{Builder, Logger, LoggerProvider};
79
pub use log_processor::{
810
BatchConfig, BatchConfigBuilder, BatchLogProcessor, BatchLogProcessorBuilder, LogProcessor,

opentelemetry-sdk/src/metrics/aggregation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::fmt;
22

33
use crate::metrics::internal::{EXPO_MAX_SCALE, EXPO_MIN_SCALE};
4-
use opentelemetry::metrics::{MetricError, MetricResult};
4+
use crate::metrics::{MetricError, MetricResult};
55

66
/// The way recorded measurements are summarized.
77
#[derive(Clone, Debug, PartialEq)]
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
use std::result;
2+
use std::sync::PoisonError;
3+
use thiserror::Error;
4+
5+
use crate::export::ExportError;
6+
7+
/// A specialized `Result` type for metric operations.
8+
pub type MetricResult<T> = result::Result<T, MetricError>;
9+
10+
/// Errors returned by the metrics API.
11+
#[derive(Error, Debug)]
12+
#[non_exhaustive]
13+
pub enum MetricError {
14+
/// Other errors not covered by specific cases.
15+
#[error("Metrics error: {0}")]
16+
Other(String),
17+
/// Invalid configuration
18+
#[error("Config error {0}")]
19+
Config(String),
20+
/// Fail to export metrics
21+
#[error("Metrics exporter {} failed with {0}", .0.exporter_name())]
22+
ExportErr(Box<dyn ExportError>),
23+
/// Invalid instrument configuration such invalid instrument name, invalid instrument description, invalid instrument unit, etc.
24+
/// See [spec](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/api.md#general-characteristics)
25+
/// for full list of requirements.
26+
#[error("Invalid instrument configuration: {0}")]
27+
InvalidInstrumentConfiguration(&'static str),
28+
}
29+
30+
impl<T: ExportError> From<T> for MetricError {
31+
fn from(err: T) -> Self {
32+
MetricError::ExportErr(Box::new(err))
33+
}
34+
}
35+
36+
impl<T> From<PoisonError<T>> for MetricError {
37+
fn from(err: PoisonError<T>) -> Self {
38+
MetricError::Other(err.to_string())
39+
}
40+
}

0 commit comments

Comments
 (0)