diff --git a/opentelemetry-appender-tracing/benches/logs.rs b/opentelemetry-appender-tracing/benches/logs.rs index 0237e4a769..0f6023f19b 100644 --- a/opentelemetry-appender-tracing/benches/logs.rs +++ b/opentelemetry-appender-tracing/benches/logs.rs @@ -15,10 +15,10 @@ use async_trait::async_trait; use criterion::{criterion_group, criterion_main, Criterion}; -use opentelemetry::logs::LogResult; use opentelemetry::{InstrumentationScope, KeyValue}; use opentelemetry_appender_tracing::layer as tracing_layer; use opentelemetry_sdk::export::logs::{LogBatch, LogExporter}; +use opentelemetry_sdk::logs::LogResult; use opentelemetry_sdk::logs::{LogProcessor, LogRecord, LoggerProvider}; use opentelemetry_sdk::Resource; use pprof::criterion::{Output, PProfProfiler}; diff --git a/opentelemetry-appender-tracing/src/layer.rs b/opentelemetry-appender-tracing/src/layer.rs index 1d1a1160fe..bbd897c8d1 100644 --- a/opentelemetry-appender-tracing/src/layer.rs +++ b/opentelemetry-appender-tracing/src/layer.rs @@ -210,12 +210,12 @@ const fn severity_of_level(level: &Level) -> Severity { mod tests { use crate::layer; use async_trait::async_trait; - use opentelemetry::logs::{LogResult, Severity}; + use opentelemetry::logs::Severity; use opentelemetry::trace::TracerProvider as _; use opentelemetry::trace::{TraceContextExt, TraceFlags, Tracer}; use opentelemetry::{logs::AnyValue, Key}; use opentelemetry_sdk::export::logs::{LogBatch, LogExporter}; - use opentelemetry_sdk::logs::{LogRecord, LoggerProvider}; + use opentelemetry_sdk::logs::{LogRecord, LogResult, LoggerProvider}; use opentelemetry_sdk::testing::logs::InMemoryLogExporter; use opentelemetry_sdk::trace; use opentelemetry_sdk::trace::{Sampler, TracerProvider}; diff --git a/opentelemetry-otlp/examples/basic-otlp-http/src/main.rs b/opentelemetry-otlp/examples/basic-otlp-http/src/main.rs index c67d6b21c5..10365606f0 100644 --- a/opentelemetry-otlp/examples/basic-otlp-http/src/main.rs +++ b/opentelemetry-otlp/examples/basic-otlp-http/src/main.rs @@ -2,7 +2,6 @@ use once_cell::sync::Lazy; use opentelemetry::{ global, - metrics::MetricError, trace::{TraceContextExt, TraceError, Tracer}, InstrumentationScope, KeyValue, }; @@ -11,7 +10,7 @@ use opentelemetry_otlp::WithExportConfig; use opentelemetry_otlp::{LogExporter, MetricExporter, Protocol, SpanExporter}; use opentelemetry_sdk::{ logs::LoggerProvider, - metrics::{PeriodicReader, SdkMeterProvider}, + metrics::{MetricError, PeriodicReader, SdkMeterProvider}, runtime, trace::{self as sdktrace, Config, TracerProvider}, }; @@ -31,7 +30,7 @@ static RESOURCE: Lazy = Lazy::new(|| { )]) }); -fn init_logs() -> Result { +fn init_logs() -> Result { let exporter = LogExporter::builder() .with_http() .with_endpoint("http://localhost:4318/v1/logs") diff --git a/opentelemetry-otlp/examples/basic-otlp/src/main.rs b/opentelemetry-otlp/examples/basic-otlp/src/main.rs index 0f99248bfd..96242458a3 100644 --- a/opentelemetry-otlp/examples/basic-otlp/src/main.rs +++ b/opentelemetry-otlp/examples/basic-otlp/src/main.rs @@ -1,12 +1,12 @@ use once_cell::sync::Lazy; -use opentelemetry::logs::LogError; -use opentelemetry::metrics::MetricError; use opentelemetry::trace::{TraceContextExt, TraceError, Tracer}; use opentelemetry::KeyValue; use opentelemetry::{global, InstrumentationScope}; use opentelemetry_appender_tracing::layer::OpenTelemetryTracingBridge; use opentelemetry_otlp::{LogExporter, MetricExporter, SpanExporter, WithExportConfig}; +use opentelemetry_sdk::logs::LogError; use opentelemetry_sdk::logs::LoggerProvider; +use opentelemetry_sdk::metrics::MetricError; use opentelemetry_sdk::metrics::{PeriodicReader, SdkMeterProvider}; use opentelemetry_sdk::trace::Config; use opentelemetry_sdk::{runtime, trace as sdktrace, Resource}; diff --git a/opentelemetry-otlp/src/exporter/http/logs.rs b/opentelemetry-otlp/src/exporter/http/logs.rs index db1932868b..985edc96ee 100644 --- a/opentelemetry-otlp/src/exporter/http/logs.rs +++ b/opentelemetry-otlp/src/exporter/http/logs.rs @@ -2,8 +2,8 @@ use std::sync::Arc; use async_trait::async_trait; use http::{header::CONTENT_TYPE, Method}; -use opentelemetry::logs::{LogError, LogResult}; use opentelemetry_sdk::export::logs::{LogBatch, LogExporter}; +use opentelemetry_sdk::logs::{LogError, LogResult}; use super::OtlpHttpClient; diff --git a/opentelemetry-otlp/src/exporter/http/metrics.rs b/opentelemetry-otlp/src/exporter/http/metrics.rs index b047cd4f32..5ba84b30e6 100644 --- a/opentelemetry-otlp/src/exporter/http/metrics.rs +++ b/opentelemetry-otlp/src/exporter/http/metrics.rs @@ -2,8 +2,8 @@ use std::sync::Arc; use async_trait::async_trait; use http::{header::CONTENT_TYPE, Method}; -use opentelemetry::metrics::{MetricError, MetricResult}; use opentelemetry_sdk::metrics::data::ResourceMetrics; +use opentelemetry_sdk::metrics::{MetricError, MetricResult}; use crate::{metric::MetricsClient, Error}; diff --git a/opentelemetry-otlp/src/exporter/http/mod.rs b/opentelemetry-otlp/src/exporter/http/mod.rs index 154871887b..1b18686a3e 100644 --- a/opentelemetry-otlp/src/exporter/http/mod.rs +++ b/opentelemetry-otlp/src/exporter/http/mod.rs @@ -223,7 +223,7 @@ impl HttpExporterBuilder { /// Create a log exporter with the current configuration #[cfg(feature = "logs")] - pub fn build_log_exporter(mut self) -> opentelemetry::logs::LogResult { + pub fn build_log_exporter(mut self) -> opentelemetry_sdk::logs::LogResult { use crate::{ OTEL_EXPORTER_OTLP_LOGS_ENDPOINT, OTEL_EXPORTER_OTLP_LOGS_HEADERS, OTEL_EXPORTER_OTLP_LOGS_TIMEOUT, @@ -244,7 +244,7 @@ impl HttpExporterBuilder { pub fn build_metrics_exporter( mut self, temporality: opentelemetry_sdk::metrics::data::Temporality, - ) -> opentelemetry::metrics::MetricResult { + ) -> opentelemetry_sdk::metrics::MetricResult { use crate::{ OTEL_EXPORTER_OTLP_METRICS_ENDPOINT, OTEL_EXPORTER_OTLP_METRICS_HEADERS, OTEL_EXPORTER_OTLP_METRICS_TIMEOUT, @@ -315,7 +315,7 @@ impl OtlpHttpClient { fn build_logs_export_body( &self, logs: LogBatch<'_>, - ) -> opentelemetry::logs::LogResult<(Vec, &'static str)> { + ) -> opentelemetry_sdk::logs::LogResult<(Vec, &'static str)> { use opentelemetry_proto::tonic::collector::logs::v1::ExportLogsServiceRequest; let resource_logs = group_logs_by_resource_and_scope(logs, &self.resource); let req = ExportLogsServiceRequest { resource_logs }; @@ -324,7 +324,7 @@ impl OtlpHttpClient { #[cfg(feature = "http-json")] Protocol::HttpJson => match serde_json::to_string_pretty(&req) { Ok(json) => Ok((json.into(), "application/json")), - Err(e) => Err(opentelemetry::logs::LogError::from(e.to_string())), + Err(e) => Err(opentelemetry_sdk::logs::LogError::from(e.to_string())), }, _ => Ok((req.encode_to_vec(), "application/x-protobuf")), } @@ -334,7 +334,7 @@ impl OtlpHttpClient { fn build_metrics_export_body( &self, metrics: &mut opentelemetry_sdk::metrics::data::ResourceMetrics, - ) -> opentelemetry::metrics::MetricResult<(Vec, &'static str)> { + ) -> opentelemetry_sdk::metrics::MetricResult<(Vec, &'static str)> { use opentelemetry_proto::tonic::collector::metrics::v1::ExportMetricsServiceRequest; let req: ExportMetricsServiceRequest = (&*metrics).into(); @@ -343,7 +343,9 @@ impl OtlpHttpClient { #[cfg(feature = "http-json")] Protocol::HttpJson => match serde_json::to_string_pretty(&req) { Ok(json) => Ok((json.into(), "application/json")), - Err(e) => Err(opentelemetry::metrics::MetricError::Other(e.to_string())), + Err(e) => Err(opentelemetry_sdk::metrics::MetricError::Other( + e.to_string(), + )), }, _ => Ok((req.encode_to_vec(), "application/x-protobuf")), } diff --git a/opentelemetry-otlp/src/exporter/tonic/logs.rs b/opentelemetry-otlp/src/exporter/tonic/logs.rs index bf9b6c9ed3..149c4b51f0 100644 --- a/opentelemetry-otlp/src/exporter/tonic/logs.rs +++ b/opentelemetry-otlp/src/exporter/tonic/logs.rs @@ -1,10 +1,10 @@ use async_trait::async_trait; use core::fmt; -use opentelemetry::logs::{LogError, LogResult}; use opentelemetry_proto::tonic::collector::logs::v1::{ logs_service_client::LogsServiceClient, ExportLogsServiceRequest, }; use opentelemetry_sdk::export::logs::{LogBatch, LogExporter}; +use opentelemetry_sdk::logs::{LogError, LogResult}; use tonic::{codegen::CompressionEncoding, service::Interceptor, transport::Channel, Request}; use opentelemetry_proto::transform::logs::tonic::group_logs_by_resource_and_scope; diff --git a/opentelemetry-otlp/src/exporter/tonic/metrics.rs b/opentelemetry-otlp/src/exporter/tonic/metrics.rs index b8a59858eb..4159222cd5 100644 --- a/opentelemetry-otlp/src/exporter/tonic/metrics.rs +++ b/opentelemetry-otlp/src/exporter/tonic/metrics.rs @@ -2,11 +2,11 @@ use core::fmt; use std::sync::Mutex; use async_trait::async_trait; -use opentelemetry::metrics::{MetricError, MetricResult}; use opentelemetry_proto::tonic::collector::metrics::v1::{ metrics_service_client::MetricsServiceClient, ExportMetricsServiceRequest, }; use opentelemetry_sdk::metrics::data::ResourceMetrics; +use opentelemetry_sdk::metrics::{MetricError, MetricResult}; use tonic::{codegen::CompressionEncoding, service::Interceptor, transport::Channel, Request}; use super::BoxInterceptor; diff --git a/opentelemetry-otlp/src/exporter/tonic/mod.rs b/opentelemetry-otlp/src/exporter/tonic/mod.rs index 7089ca045a..e55d13f526 100644 --- a/opentelemetry-otlp/src/exporter/tonic/mod.rs +++ b/opentelemetry-otlp/src/exporter/tonic/mod.rs @@ -254,7 +254,7 @@ impl TonicExporterBuilder { #[cfg(feature = "logs")] pub(crate) fn build_log_exporter( self, - ) -> Result { + ) -> Result { use crate::exporter::tonic::logs::TonicLogsClient; let (channel, interceptor, compression) = self.build_channel( @@ -274,7 +274,7 @@ impl TonicExporterBuilder { pub(crate) fn build_metrics_exporter( self, temporality: opentelemetry_sdk::metrics::data::Temporality, - ) -> opentelemetry::metrics::MetricResult { + ) -> opentelemetry_sdk::metrics::MetricResult { use crate::MetricExporter; use metrics::TonicMetricsClient; diff --git a/opentelemetry-otlp/src/lib.rs b/opentelemetry-otlp/src/lib.rs index 4429f6fda9..c8d7c0308a 100644 --- a/opentelemetry-otlp/src/lib.rs +++ b/opentelemetry-otlp/src/lib.rs @@ -391,6 +391,12 @@ impl ExportError for Error { } } +impl opentelemetry::trace::ExportError for Error { + fn exporter_name(&self) -> &'static str { + "otlp" + } +} + /// The communication protocol to use when exporting data. #[cfg_attr(feature = "serialize", derive(Deserialize, Serialize))] #[derive(Clone, Copy, Debug, Eq, PartialEq)] diff --git a/opentelemetry-otlp/src/logs.rs b/opentelemetry-otlp/src/logs.rs index 42727a8d74..a0c09ab28d 100644 --- a/opentelemetry-otlp/src/logs.rs +++ b/opentelemetry-otlp/src/logs.rs @@ -5,7 +5,7 @@ use async_trait::async_trait; use std::fmt::Debug; -use opentelemetry::logs::LogResult; +use opentelemetry_sdk::logs::LogResult; use opentelemetry_sdk::export::logs::LogBatch; @@ -62,14 +62,14 @@ impl LogExporterBuilder { #[cfg(feature = "grpc-tonic")] impl LogExporterBuilder { - pub fn build(self) -> Result { + pub fn build(self) -> Result { self.client.0.build_log_exporter() } } #[cfg(any(feature = "http-proto", feature = "http-json"))] impl LogExporterBuilder { - pub fn build(self) -> Result { + pub fn build(self) -> Result { self.client.0.build_log_exporter() } } diff --git a/opentelemetry-otlp/src/metric.rs b/opentelemetry-otlp/src/metric.rs index e2b3408174..3d5f9b981f 100644 --- a/opentelemetry-otlp/src/metric.rs +++ b/opentelemetry-otlp/src/metric.rs @@ -16,7 +16,7 @@ use crate::NoExporterBuilderSet; use async_trait::async_trait; use core::fmt; -use opentelemetry::metrics::MetricResult; +use opentelemetry_sdk::metrics::MetricResult; use opentelemetry_sdk::metrics::{ data::{ResourceMetrics, Temporality}, diff --git a/opentelemetry-otlp/tests/integration_test/tests/logs.rs b/opentelemetry-otlp/tests/integration_test/tests/logs.rs index 0fa4b5630a..13068d0938 100644 --- a/opentelemetry-otlp/tests/integration_test/tests/logs.rs +++ b/opentelemetry-otlp/tests/integration_test/tests/logs.rs @@ -2,11 +2,10 @@ use integration_test_runner::logs_asserter::{read_logs_from_json, LogsAsserter}; use log::{info, Level}; -use opentelemetry::logs::LogError; use opentelemetry::KeyValue; use opentelemetry_appender_log::OpenTelemetryLogBridge; use opentelemetry_otlp::LogExporter; -use opentelemetry_sdk::logs::LoggerProvider; +use opentelemetry_sdk::logs::{LogError, LoggerProvider}; use opentelemetry_sdk::{logs as sdklogs, runtime, Resource}; use std::error::Error; use std::fs::File; diff --git a/opentelemetry-sdk/CHANGELOG.md b/opentelemetry-sdk/CHANGELOG.md index 96967fe421..812fe80672 100644 --- a/opentelemetry-sdk/CHANGELOG.md +++ b/opentelemetry-sdk/CHANGELOG.md @@ -34,6 +34,18 @@ - Pin url version to `2.5.2`. The higher version breaks the build refer: [servo/rust-url#992.](https://github.com/servo/rust-url/issues/992) The `url` crate is used when `jaeger_remote_sampler` feature is enabled. +- **BREAKING**: [#2266](https://github.com/open-telemetry/opentelemetry-rust/pull/2266) + - Moved `ExportError` trait from `opentelemetry::ExportError` to `opentelemetry_sdk::export::ExportError` + - Moved `LogError` enum from `opentelemetry::logs::LogError` to `opentelemetry_sdk::logs::LogError` + - Moved `LogResult` type alias from `opentelemetry::logs::LogResult` to `opentelemetry_sdk::logs::LogResult` + - Renamed `opentelemetry::metrics::Result` type alias to `opentelemetry::metrics::MetricResult` + - Renamed `opentelemetry::metrics::MetricsError` enum to `opentelemetry::metrics::MetricError` + - Moved `MetricError` enum from `opentelemetry::metrics::MetricError` to `opentelemetry_sdk::metrics::MetricError` + - Moved `MetricResult` type alias from `opentelemetry::metrics::MetricResult` to `opentelemetry_sdk::metrics::MetricResult` + + - Users calling public APIs that return these constructs (e.g, LoggerProvider::shutdown(), MeterProvider::force_flush()) should now import them from the SDK instead of the API. + - Developers creating custom exporters should ensure they import these constructs from the SDK, not the API. + ## v0.26.0 Released 2024-Sep-30 diff --git a/opentelemetry-sdk/benches/log.rs b/opentelemetry-sdk/benches/log.rs index ca8a76a414..27403aa9d7 100644 --- a/opentelemetry-sdk/benches/log.rs +++ b/opentelemetry-sdk/benches/log.rs @@ -20,13 +20,11 @@ use std::time::SystemTime; use criterion::{criterion_group, criterion_main, Criterion}; -use opentelemetry::logs::{ - AnyValue, LogRecord as _, LogResult, Logger as _, LoggerProvider as _, Severity, -}; +use opentelemetry::logs::{AnyValue, LogRecord as _, Logger as _, LoggerProvider as _, Severity}; use opentelemetry::trace::Tracer; use opentelemetry::trace::TracerProvider as _; use opentelemetry::{InstrumentationScope, Key}; -use opentelemetry_sdk::logs::{LogProcessor, LogRecord, Logger, LoggerProvider}; +use opentelemetry_sdk::logs::{LogProcessor, LogRecord, LogResult, Logger, LoggerProvider}; use opentelemetry_sdk::trace; use opentelemetry_sdk::trace::{Sampler, TracerProvider}; diff --git a/opentelemetry-sdk/benches/log_exporter.rs b/opentelemetry-sdk/benches/log_exporter.rs index c3c027f3e1..c2ecb78ce9 100644 --- a/opentelemetry-sdk/benches/log_exporter.rs +++ b/opentelemetry-sdk/benches/log_exporter.rs @@ -16,7 +16,8 @@ use std::time::SystemTime; use async_trait::async_trait; use criterion::{criterion_group, criterion_main, Criterion}; -use opentelemetry::logs::{LogRecord as _, LogResult, Logger as _, LoggerProvider as _, Severity}; +use opentelemetry::logs::{LogRecord as _, Logger as _, LoggerProvider as _, Severity}; +use opentelemetry_sdk::logs::LogResult; use opentelemetry::InstrumentationScope; use opentelemetry_sdk::export::logs::LogBatch; diff --git a/opentelemetry-sdk/benches/log_processor.rs b/opentelemetry-sdk/benches/log_processor.rs index 03cd71549c..87cd242d0d 100644 --- a/opentelemetry-sdk/benches/log_processor.rs +++ b/opentelemetry-sdk/benches/log_processor.rs @@ -19,10 +19,10 @@ use std::{ use criterion::{criterion_group, criterion_main, Criterion}; use opentelemetry::{ - logs::{LogRecord as _, LogResult, Logger as _, LoggerProvider as _, Severity}, + logs::{LogRecord as _, Logger as _, LoggerProvider as _, Severity}, InstrumentationScope, }; -use opentelemetry_sdk::logs::{LogProcessor, LogRecord, Logger, LoggerProvider}; +use opentelemetry_sdk::logs::{LogProcessor, LogRecord, LogResult, Logger, LoggerProvider}; // Run this benchmark with: // cargo bench --bench log_processor diff --git a/opentelemetry-sdk/benches/metric.rs b/opentelemetry-sdk/benches/metric.rs index 0e36debb50..77de656bb8 100644 --- a/opentelemetry-sdk/benches/metric.rs +++ b/opentelemetry-sdk/benches/metric.rs @@ -3,7 +3,7 @@ use std::sync::{Arc, Weak}; use criterion::{criterion_group, criterion_main, Bencher, Criterion}; use opentelemetry::{ - metrics::{Counter, Histogram, MeterProvider as _, MetricResult}, + metrics::{Counter, Histogram, MeterProvider as _}, Key, KeyValue, }; use opentelemetry_sdk::{ @@ -11,8 +11,8 @@ use opentelemetry_sdk::{ data::{ResourceMetrics, Temporality}, new_view, reader::MetricReader, - Aggregation, Instrument, InstrumentKind, ManualReader, Pipeline, SdkMeterProvider, Stream, - View, + Aggregation, Instrument, InstrumentKind, ManualReader, MetricResult, Pipeline, + SdkMeterProvider, Stream, View, }, Resource, }; diff --git a/opentelemetry/src/global/error_handler.rs b/opentelemetry-sdk/src/error.rs similarity index 88% rename from opentelemetry/src/global/error_handler.rs rename to opentelemetry-sdk/src/error.rs index 391fa25f63..115da17b78 100644 --- a/opentelemetry/src/global/error_handler.rs +++ b/opentelemetry-sdk/src/error.rs @@ -1,12 +1,13 @@ +//! Wrapper for error from trace, logs and metrics part of open telemetry. use std::sync::PoisonError; #[cfg(feature = "logs")] use crate::logs::LogError; #[cfg(feature = "metrics")] use crate::metrics::MetricError; -use crate::propagation::PropagationError; +use opentelemetry::propagation::PropagationError; #[cfg(feature = "trace")] -use crate::trace::TraceError; +use opentelemetry::trace::TraceError; /// Wrapper for error from both tracing and metrics part of open telemetry. #[derive(thiserror::Error, Debug)] diff --git a/opentelemetry-sdk/src/export/logs/mod.rs b/opentelemetry-sdk/src/export/logs/mod.rs index 2656544ce0..098c6b8427 100644 --- a/opentelemetry-sdk/src/export/logs/mod.rs +++ b/opentelemetry-sdk/src/export/logs/mod.rs @@ -1,10 +1,10 @@ //! Log exporters use crate::logs::LogRecord; +use crate::logs::{LogError, LogResult}; use crate::Resource; use async_trait::async_trait; #[cfg(feature = "logs_level_enabled")] use opentelemetry::logs::Severity; -use opentelemetry::logs::{LogError, LogResult}; use opentelemetry::InstrumentationScope; use std::fmt::Debug; diff --git a/opentelemetry-sdk/src/export/mod.rs b/opentelemetry-sdk/src/export/mod.rs index c59a7028a5..21dc2b570c 100644 --- a/opentelemetry-sdk/src/export/mod.rs +++ b/opentelemetry-sdk/src/export/mod.rs @@ -8,4 +8,8 @@ pub mod logs; #[cfg_attr(docsrs, doc(cfg(feature = "trace")))] pub mod trace; -pub use opentelemetry::ExportError; +/// Trait for errors returned by exporters +pub trait ExportError: std::error::Error + Send + Sync + 'static { + /// The name of exporter that returned this error + fn exporter_name(&self) -> &'static str; +} diff --git a/opentelemetry-sdk/src/lib.rs b/opentelemetry-sdk/src/lib.rs index 273cb183c8..6f351c2459 100644 --- a/opentelemetry-sdk/src/lib.rs +++ b/opentelemetry-sdk/src/lib.rs @@ -148,3 +148,5 @@ pub mod util; #[doc(inline)] pub use resource::Resource; + +pub mod error; diff --git a/opentelemetry-sdk/src/logs/error.rs b/opentelemetry-sdk/src/logs/error.rs new file mode 100644 index 0000000000..1cbcd29e2e --- /dev/null +++ b/opentelemetry-sdk/src/logs/error.rs @@ -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 = Result; + +#[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), + + /// 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), +} + +impl From for LogError +where + T: ExportError, +{ + fn from(err: T) -> Self { + LogError::ExportFailed(Box::new(err)) + } +} + +impl From 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 From> for LogError { + fn from(err: PoisonError) -> Self { + LogError::Other(err.to_string().into()) + } +} +/// Wrap type for string +#[derive(Error, Debug)] +#[error("{0}")] +struct Custom(String); diff --git a/opentelemetry-sdk/src/logs/log_emitter.rs b/opentelemetry-sdk/src/logs/log_emitter.rs index 0a199f9d85..600e02c49e 100644 --- a/opentelemetry-sdk/src/logs/log_emitter.rs +++ b/opentelemetry-sdk/src/logs/log_emitter.rs @@ -1,11 +1,7 @@ use super::{BatchLogProcessor, LogProcessor, LogRecord, SimpleLogProcessor, TraceContext}; use crate::{export::logs::LogExporter, runtime::RuntimeChannel, Resource}; -use opentelemetry::{ - logs::{LogError, LogResult}, - otel_debug, - trace::TraceContextExt, - Context, InstrumentationScope, -}; +use crate::{logs::LogError, logs::LogResult}; +use opentelemetry::{otel_debug, trace::TraceContextExt, Context, InstrumentationScope}; #[cfg(feature = "logs_level_enabled")] use opentelemetry::logs::Severity; diff --git a/opentelemetry-sdk/src/logs/log_processor.rs b/opentelemetry-sdk/src/logs/log_processor.rs index fa5308159f..258c23c811 100644 --- a/opentelemetry-sdk/src/logs/log_processor.rs +++ b/opentelemetry-sdk/src/logs/log_processor.rs @@ -1,6 +1,6 @@ use crate::{ export::logs::{ExportResult, LogBatch, LogExporter}, - logs::LogRecord, + logs::{LogError, LogRecord, LogResult}, runtime::{RuntimeChannel, TrySend}, Resource, }; @@ -11,10 +11,7 @@ use futures_util::{ }; #[cfg(feature = "logs_level_enabled")] use opentelemetry::logs::Severity; -use opentelemetry::{ - logs::{LogError, LogResult}, - otel_debug, otel_error, otel_warn, InstrumentationScope, -}; +use opentelemetry::{otel_debug, otel_error, otel_warn, InstrumentationScope}; use std::sync::atomic::AtomicBool; use std::{cmp::min, env, sync::Mutex}; @@ -533,6 +530,7 @@ mod tests { }; use crate::export::logs::{LogBatch, LogExporter}; use crate::logs::LogRecord; + use crate::logs::LogResult; use crate::testing::logs::InMemoryLogExporterBuilder; use crate::{ logs::{ @@ -550,7 +548,7 @@ mod tests { use opentelemetry::logs::AnyValue; use opentelemetry::logs::LogRecord as _; use opentelemetry::logs::{Logger, LoggerProvider as _}; - use opentelemetry::{logs::LogResult, KeyValue}; + use opentelemetry::KeyValue; use opentelemetry::{InstrumentationScope, Key}; use std::sync::atomic::{AtomicUsize, Ordering}; use std::sync::{Arc, Mutex}; diff --git a/opentelemetry-sdk/src/logs/mod.rs b/opentelemetry-sdk/src/logs/mod.rs index a3ea712bea..2dba806056 100644 --- a/opentelemetry-sdk/src/logs/mod.rs +++ b/opentelemetry-sdk/src/logs/mod.rs @@ -1,8 +1,10 @@ //! # OpenTelemetry Log SDK +mod error; mod log_emitter; mod log_processor; pub(crate) mod record; +pub use error::{LogError, LogResult}; pub use log_emitter::{Builder, Logger, LoggerProvider}; pub use log_processor::{ BatchConfig, BatchConfigBuilder, BatchLogProcessor, BatchLogProcessorBuilder, LogProcessor, diff --git a/opentelemetry-sdk/src/metrics/aggregation.rs b/opentelemetry-sdk/src/metrics/aggregation.rs index 6ccd564870..1788b6b264 100644 --- a/opentelemetry-sdk/src/metrics/aggregation.rs +++ b/opentelemetry-sdk/src/metrics/aggregation.rs @@ -1,7 +1,7 @@ use std::fmt; use crate::metrics::internal::{EXPO_MAX_SCALE, EXPO_MIN_SCALE}; -use opentelemetry::metrics::{MetricError, MetricResult}; +use crate::metrics::{MetricError, MetricResult}; /// The way recorded measurements are summarized. #[derive(Clone, Debug, PartialEq)] @@ -153,7 +153,7 @@ mod tests { internal::{EXPO_MAX_SCALE, EXPO_MIN_SCALE}, Aggregation, }; - use opentelemetry::metrics::{MetricError, MetricResult}; + use crate::metrics::{MetricError, MetricResult}; #[test] fn validate_aggregation() { diff --git a/opentelemetry-sdk/src/metrics/error.rs b/opentelemetry-sdk/src/metrics/error.rs new file mode 100644 index 0000000000..13e0e7b752 --- /dev/null +++ b/opentelemetry-sdk/src/metrics/error.rs @@ -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 = result::Result; + +/// 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), + /// 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 From for MetricError { + fn from(err: T) -> Self { + MetricError::ExportErr(Box::new(err)) + } +} + +impl From> for MetricError { + fn from(err: PoisonError) -> Self { + MetricError::Other(err.to_string()) + } +} diff --git a/opentelemetry-sdk/src/metrics/exporter.rs b/opentelemetry-sdk/src/metrics/exporter.rs index f30685be76..a4e192c414 100644 --- a/opentelemetry-sdk/src/metrics/exporter.rs +++ b/opentelemetry-sdk/src/metrics/exporter.rs @@ -1,7 +1,7 @@ //! Interfaces for exporting metrics use async_trait::async_trait; -use opentelemetry::metrics::MetricResult; +use crate::metrics::MetricResult; use crate::metrics::data::ResourceMetrics; diff --git a/opentelemetry-sdk/src/metrics/manual_reader.rs b/opentelemetry-sdk/src/metrics/manual_reader.rs index f64c61b91d..21bd2a3976 100644 --- a/opentelemetry-sdk/src/metrics/manual_reader.rs +++ b/opentelemetry-sdk/src/metrics/manual_reader.rs @@ -3,10 +3,9 @@ use std::{ sync::{Mutex, Weak}, }; -use opentelemetry::{ - metrics::{MetricError, MetricResult}, - otel_debug, -}; +use opentelemetry::otel_debug; + +use crate::metrics::{MetricError, MetricResult}; use super::{ data::{ResourceMetrics, Temporality}, diff --git a/opentelemetry-sdk/src/metrics/meter.rs b/opentelemetry-sdk/src/metrics/meter.rs index 430bf5e57b..3c3ad37352 100644 --- a/opentelemetry-sdk/src/metrics/meter.rs +++ b/opentelemetry-sdk/src/metrics/meter.rs @@ -4,8 +4,8 @@ use std::{borrow::Cow, sync::Arc}; use opentelemetry::{ metrics::{ AsyncInstrumentBuilder, Counter, Gauge, Histogram, HistogramBuilder, InstrumentBuilder, - InstrumentProvider, MetricError, MetricResult, ObservableCounter, ObservableGauge, - ObservableUpDownCounter, UpDownCounter, + InstrumentProvider, ObservableCounter, ObservableGauge, ObservableUpDownCounter, + UpDownCounter, }, otel_error, InstrumentationScope, }; @@ -14,6 +14,7 @@ use crate::metrics::{ instrument::{Instrument, InstrumentKind, Observable, ResolvedMeasures}, internal::{self, Number}, pipeline::{Pipelines, Resolver}, + MetricError, MetricResult, }; use super::noop::NoopSyncInstrument; @@ -633,7 +634,7 @@ where mod tests { use std::borrow::Cow; - use opentelemetry::metrics::MetricError; + use crate::metrics::MetricError; use super::{ validate_instrument_name, validate_instrument_unit, INSTRUMENT_NAME_FIRST_ALPHABETIC, diff --git a/opentelemetry-sdk/src/metrics/meter_provider.rs b/opentelemetry-sdk/src/metrics/meter_provider.rs index b7aec1ca25..2e9895db1e 100644 --- a/opentelemetry-sdk/src/metrics/meter_provider.rs +++ b/opentelemetry-sdk/src/metrics/meter_provider.rs @@ -8,10 +8,11 @@ use std::{ }; use opentelemetry::{ - metrics::{Meter, MeterProvider, MetricError, MetricResult}, + metrics::{Meter, MeterProvider}, otel_debug, otel_error, InstrumentationScope, }; +use crate::metrics::{MetricError, MetricResult}; use crate::Resource; use super::{ diff --git a/opentelemetry-sdk/src/metrics/mod.rs b/opentelemetry-sdk/src/metrics/mod.rs index 0eb4eabc86..f8c440050d 100644 --- a/opentelemetry-sdk/src/metrics/mod.rs +++ b/opentelemetry-sdk/src/metrics/mod.rs @@ -41,6 +41,7 @@ pub(crate) mod aggregation; pub mod data; +mod error; pub mod exporter; pub(crate) mod instrument; pub(crate) mod internal; @@ -54,6 +55,7 @@ pub mod reader; pub(crate) mod view; pub use aggregation::*; +pub use error::{MetricError, MetricResult}; pub use instrument::*; pub use manual_reader::*; pub use meter_provider::*; diff --git a/opentelemetry-sdk/src/metrics/periodic_reader.rs b/opentelemetry-sdk/src/metrics/periodic_reader.rs index 1cab53edd1..6484d25126 100644 --- a/opentelemetry-sdk/src/metrics/periodic_reader.rs +++ b/opentelemetry-sdk/src/metrics/periodic_reader.rs @@ -11,14 +11,11 @@ use futures_util::{ stream::{self, FusedStream}, StreamExt, }; -use opentelemetry::{ - metrics::{MetricError, MetricResult}, - otel_debug, otel_error, -}; +use opentelemetry::{otel_debug, otel_error}; use crate::runtime::Runtime; use crate::{ - metrics::{exporter::PushMetricExporter, reader::SdkProducer}, + metrics::{exporter::PushMetricExporter, reader::SdkProducer, MetricError, MetricResult}, Resource, }; @@ -407,11 +404,12 @@ impl MetricReader for PeriodicReader { #[cfg(all(test, feature = "testing"))] mod tests { use super::PeriodicReader; + use crate::metrics::MetricError; use crate::{ metrics::data::ResourceMetrics, metrics::reader::MetricReader, metrics::SdkMeterProvider, runtime, testing::metrics::InMemoryMetricExporter, Resource, }; - use opentelemetry::metrics::{MeterProvider, MetricError}; + use opentelemetry::metrics::MeterProvider; use std::sync::mpsc; #[test] diff --git a/opentelemetry-sdk/src/metrics/pipeline.rs b/opentelemetry-sdk/src/metrics/pipeline.rs index acf4605d13..8da41f38fb 100644 --- a/opentelemetry-sdk/src/metrics/pipeline.rs +++ b/opentelemetry-sdk/src/metrics/pipeline.rs @@ -5,10 +5,7 @@ use std::{ sync::{Arc, Mutex}, }; -use opentelemetry::{ - metrics::{MetricError, MetricResult}, - otel_debug, InstrumentationScope, KeyValue, -}; +use opentelemetry::{otel_debug, InstrumentationScope, KeyValue}; use crate::{ metrics::{ @@ -20,6 +17,7 @@ use crate::{ internal::Number, reader::{MetricReader, SdkProducer}, view::View, + MetricError, MetricResult, }, Resource, }; diff --git a/opentelemetry-sdk/src/metrics/reader.rs b/opentelemetry-sdk/src/metrics/reader.rs index 1a98ffbb03..b700c13230 100644 --- a/opentelemetry-sdk/src/metrics/reader.rs +++ b/opentelemetry-sdk/src/metrics/reader.rs @@ -1,7 +1,7 @@ //! Interfaces for reading and producing metrics use std::{fmt, sync::Weak}; -use opentelemetry::metrics::MetricResult; +use crate::metrics::MetricResult; use super::{ data::{ResourceMetrics, Temporality}, diff --git a/opentelemetry-sdk/src/metrics/view.rs b/opentelemetry-sdk/src/metrics/view.rs index 3913412cb7..b4c4a8a4d5 100644 --- a/opentelemetry-sdk/src/metrics/view.rs +++ b/opentelemetry-sdk/src/metrics/view.rs @@ -1,6 +1,6 @@ use super::instrument::{Instrument, Stream}; +use crate::metrics::{MetricError, MetricResult}; use glob::Pattern; -use opentelemetry::metrics::{MetricError, MetricResult}; fn empty_view(_inst: &Instrument) -> Option { None diff --git a/opentelemetry-sdk/src/testing/logs/in_memory_exporter.rs b/opentelemetry-sdk/src/testing/logs/in_memory_exporter.rs index 7bcbd996af..cac026c663 100644 --- a/opentelemetry-sdk/src/testing/logs/in_memory_exporter.rs +++ b/opentelemetry-sdk/src/testing/logs/in_memory_exporter.rs @@ -1,8 +1,8 @@ use crate::export::logs::{LogBatch, LogExporter}; use crate::logs::LogRecord; +use crate::logs::{LogError, LogResult}; use crate::Resource; use async_trait::async_trait; -use opentelemetry::logs::{LogError, LogResult}; use opentelemetry::InstrumentationScope; use std::borrow::Cow; use std::sync::{Arc, Mutex}; diff --git a/opentelemetry-sdk/src/testing/metrics/in_memory_exporter.rs b/opentelemetry-sdk/src/testing/metrics/in_memory_exporter.rs index d5c8a7494c..223c84fe70 100644 --- a/opentelemetry-sdk/src/testing/metrics/in_memory_exporter.rs +++ b/opentelemetry-sdk/src/testing/metrics/in_memory_exporter.rs @@ -1,9 +1,9 @@ use crate::metrics::data; use crate::metrics::data::{Histogram, Metric, ResourceMetrics, ScopeMetrics, Temporality}; use crate::metrics::exporter::PushMetricExporter; +use crate::metrics::MetricError; +use crate::metrics::MetricResult; use async_trait::async_trait; -use opentelemetry::metrics::MetricError; -use opentelemetry::metrics::MetricResult; use std::collections::VecDeque; use std::fmt; use std::sync::{Arc, Mutex}; diff --git a/opentelemetry-sdk/src/testing/metrics/metric_reader.rs b/opentelemetry-sdk/src/testing/metrics/metric_reader.rs index a3c3cf6f49..96c3c939ba 100644 --- a/opentelemetry-sdk/src/testing/metrics/metric_reader.rs +++ b/opentelemetry-sdk/src/testing/metrics/metric_reader.rs @@ -1,12 +1,12 @@ use std::sync::{Arc, Mutex, Weak}; +use crate::metrics::MetricResult; use crate::metrics::{ data::{ResourceMetrics, Temporality}, pipeline::Pipeline, reader::MetricReader, InstrumentKind, }; -use opentelemetry::metrics::MetricResult; #[derive(Debug, Clone)] pub struct TestMetricReader { diff --git a/opentelemetry-sdk/src/testing/trace/span_exporters.rs b/opentelemetry-sdk/src/testing/trace/span_exporters.rs index f8a0776318..e9996e3fc8 100644 --- a/opentelemetry-sdk/src/testing/trace/span_exporters.rs +++ b/opentelemetry-sdk/src/testing/trace/span_exporters.rs @@ -1,8 +1,5 @@ use crate::{ - export::{ - trace::{ExportResult, SpanData, SpanExporter}, - ExportError, - }, + export::trace::{ExportResult, SpanData, SpanExporter}, trace::{SpanEvents, SpanLinks}, }; use futures_util::future::BoxFuture; @@ -80,7 +77,7 @@ pub struct TestExportError(String); impl std::error::Error for TestExportError {} -impl ExportError for TestExportError { +impl opentelemetry::trace::ExportError for TestExportError { fn exporter_name(&self) -> &'static str { "test" } diff --git a/opentelemetry-stdout/src/logs/exporter.rs b/opentelemetry-stdout/src/logs/exporter.rs index 8a2243df0c..c5edb880bf 100644 --- a/opentelemetry-stdout/src/logs/exporter.rs +++ b/opentelemetry-stdout/src/logs/exporter.rs @@ -1,8 +1,8 @@ use async_trait::async_trait; use chrono::{DateTime, Utc}; use core::fmt; -use opentelemetry::logs::LogResult; use opentelemetry_sdk::export::logs::LogBatch; +use opentelemetry_sdk::logs::LogResult; use opentelemetry_sdk::Resource; use std::sync::atomic; diff --git a/opentelemetry-stdout/src/metrics/exporter.rs b/opentelemetry-stdout/src/metrics/exporter.rs index ed82f8a8ca..d9e191b8aa 100644 --- a/opentelemetry-stdout/src/metrics/exporter.rs +++ b/opentelemetry-stdout/src/metrics/exporter.rs @@ -1,11 +1,11 @@ use async_trait::async_trait; use chrono::{DateTime, Utc}; use core::{f64, fmt}; -use opentelemetry::metrics::{MetricError, MetricResult}; use opentelemetry_sdk::metrics::{ data::{self, ScopeMetrics, Temporality}, exporter::PushMetricExporter, }; +use opentelemetry_sdk::metrics::{MetricError, MetricResult}; use std::fmt::Debug; use std::sync::atomic; diff --git a/opentelemetry-zipkin/src/exporter/mod.rs b/opentelemetry-zipkin/src/exporter/mod.rs index e7466c6a2d..1ddd6c2b5b 100644 --- a/opentelemetry-zipkin/src/exporter/mod.rs +++ b/opentelemetry-zipkin/src/exporter/mod.rs @@ -252,3 +252,9 @@ impl ExportError for Error { "zipkin" } } + +impl opentelemetry::trace::ExportError for Error { + fn exporter_name(&self) -> &'static str { + "zipkin" + } +} diff --git a/opentelemetry/CHANGELOG.md b/opentelemetry/CHANGELOG.md index d208cbe7b9..878a10d80f 100644 --- a/opentelemetry/CHANGELOG.md +++ b/opentelemetry/CHANGELOG.md @@ -41,6 +41,15 @@ let counter = meter.u64_counter("my_counter").build(); - **Breaking change**: replaced `InstrumentationScope` public attributes by getters [#2275](https://github.com/open-telemetry/opentelemetry-rust/pull/2275) +- [#2266](https://github.com/open-telemetry/opentelemetry-rust/pull/2266) + - Moved `ExportError` trait from `opentelemetry::ExportError` to `opentelemetry_sdk::export::ExportError` + - Created new trait `opentelemetry::trace::ExportError` for trace API. This would be eventually be consolidated with ExportError in the SDK. + - Moved `LogError` enum from `opentelemetry::logs::LogError` to `opentelemetry_sdk::logs::LogError` + - Moved `LogResult` type alias from `opentelemetry::logs::LogResult` to `opentelemetry_sdk::logs::LogResult` + - Moved `MetricError` enum from `opentelemetry::metrics::MetricError` to `opentelemetry_sdk::metrics::MetricError` + - Moved `MetricResult` type alias from `opentelemetry::metrics::MetricResult` to `opentelemetry_sdk::metrics::MetricResult` + These changes shouldn't directly affect the users of OpenTelemetry crate, as these constructs are used in SDK and Exporters. If you are an author of an sdk component/plug-in, like an exporter etc. please use these types from sdk. Refer [CHANGELOG.md](https://github.com/open-telemetry/opentelemetry-rust/blob/main/opentelemetry-sdk/CHANGELOG.md) for more details, under same version section. + ## v0.26.0 Released 2024-Sep-30 diff --git a/opentelemetry/src/common.rs b/opentelemetry/src/common.rs index 078831a64e..85fa6e7f9d 100644 --- a/opentelemetry/src/common.rs +++ b/opentelemetry/src/common.rs @@ -399,12 +399,6 @@ impl KeyValue { } } -/// Marker trait for errors returned by exporters -pub trait ExportError: std::error::Error + Send + Sync + 'static { - /// The name of exporter that returned this error - fn exporter_name(&self) -> &'static str; -} - /// Information about a library or crate providing instrumentation. /// /// An instrumentation scope should be named to follow any naming conventions diff --git a/opentelemetry/src/global/mod.rs b/opentelemetry/src/global/mod.rs index 5f27b0e08b..182364a18c 100644 --- a/opentelemetry/src/global/mod.rs +++ b/opentelemetry/src/global/mod.rs @@ -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; @@ -138,7 +137,6 @@ mod metrics; mod propagation; #[cfg(feature = "trace")] mod trace; -pub use error_handler::Error; #[cfg(feature = "metrics")] #[cfg_attr(docsrs, doc(cfg(feature = "metrics")))] diff --git a/opentelemetry/src/lib.rs b/opentelemetry/src/lib.rs index 1c8d07caf7..f760aa1017 100644 --- a/opentelemetry/src/lib.rs +++ b/opentelemetry/src/lib.rs @@ -204,8 +204,7 @@ mod common; pub mod testing; pub use common::{ - Array, ExportError, InstrumentationScope, InstrumentationScopeBuilder, Key, KeyValue, - StringValue, Value, + Array, InstrumentationScope, InstrumentationScopeBuilder, Key, KeyValue, StringValue, Value, }; #[cfg(feature = "metrics")] diff --git a/opentelemetry/src/logs/mod.rs b/opentelemetry/src/logs/mod.rs index 1a27edb2e0..e57684bc0f 100644 --- a/opentelemetry/src/logs/mod.rs +++ b/opentelemetry/src/logs/mod.rs @@ -2,11 +2,6 @@ /// This API is not intended to be called by application developers directly. /// It is provided for logging library authors to build log appenders, that /// bridges existing logging systems with OpenTelemetry. -use crate::ExportError; - -use std::{sync::PoisonError, time::Duration}; -use thiserror::Error; - mod logger; mod noop; mod record; @@ -14,62 +9,3 @@ mod record; pub use logger::{Logger, LoggerProvider}; pub use noop::NoopLoggerProvider; pub use record::{AnyValue, LogRecord, Severity}; - -/// Describe the result of operations in log SDK. -pub type LogResult = Result; - -#[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), - - /// 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), -} - -impl From for LogError -where - T: ExportError, -{ - fn from(err: T) -> Self { - LogError::ExportFailed(Box::new(err)) - } -} - -impl From 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 From> for LogError { - fn from(err: PoisonError) -> Self { - LogError::Other(err.to_string().into()) - } -} -/// Wrap type for string -#[derive(Error, Debug)] -#[error("{0}")] -struct Custom(String); diff --git a/opentelemetry/src/metrics/mod.rs b/opentelemetry/src/metrics/mod.rs index 6c3a4381fb..075d5cccbe 100644 --- a/opentelemetry/src/metrics/mod.rs +++ b/opentelemetry/src/metrics/mod.rs @@ -1,16 +1,13 @@ //! # OpenTelemetry Metrics API use std::hash::{Hash, Hasher}; -use std::result; use std::sync::Arc; -use std::sync::PoisonError; -use thiserror::Error; mod instruments; mod meter; pub(crate) mod noop; -use crate::{Array, ExportError, KeyValue, Value}; +use crate::{Array, KeyValue, Value}; pub use instruments::{ counter::{Counter, ObservableCounter}, gauge::{Gauge, ObservableGauge}, @@ -21,41 +18,6 @@ pub use instruments::{ }; pub use meter::{Meter, MeterProvider}; -/// A specialized `Result` type for metric operations. -pub type MetricResult = result::Result; - -/// 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), - /// 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 From for MetricError { - fn from(err: T) -> Self { - MetricError::ExportErr(Box::new(err)) - } -} - -impl From> for MetricError { - fn from(err: PoisonError) -> Self { - MetricError::Other(err.to_string()) - } -} - struct F64Hashable(f64); impl PartialEq for F64Hashable { diff --git a/opentelemetry/src/trace/mod.rs b/opentelemetry/src/trace/mod.rs index 3f0f74e90e..09443c4b4c 100644 --- a/opentelemetry/src/trace/mod.rs +++ b/opentelemetry/src/trace/mod.rs @@ -186,9 +186,17 @@ pub use self::{ tracer::{SamplingDecision, SamplingResult, SpanBuilder, Tracer}, tracer_provider::TracerProvider, }; -use crate::{ExportError, KeyValue}; +use crate::KeyValue; use std::sync::PoisonError; +// TODO - Move ExportError and TraceError to opentelemetry-sdk + +/// Trait for errors returned by exporters +pub trait ExportError: std::error::Error + Send + Sync + 'static { + /// The name of exporter that returned this error + fn exporter_name(&self) -> &'static str; +} + /// Describe the result of operations in tracing API. pub type TraceResult = Result; diff --git a/stress/src/logs.rs b/stress/src/logs.rs index 17fcf2833e..1ede37b1ee 100644 --- a/stress/src/logs.rs +++ b/stress/src/logs.rs @@ -28,11 +28,11 @@ impl LogProcessor for NoOpLogProcessor { ) { } - fn force_flush(&self) -> opentelemetry::logs::LogResult<()> { + fn force_flush(&self) -> opentelemetry_sdk::logs::LogResult<()> { Ok(()) } - fn shutdown(&self) -> opentelemetry::logs::LogResult<()> { + fn shutdown(&self) -> opentelemetry_sdk::logs::LogResult<()> { Ok(()) } }