From ebc902bb8963d614930d4eb673f0aff024bf23fd Mon Sep 17 00:00:00 2001 From: "zhongyang.wu" Date: Sun, 29 Nov 2020 18:47:03 -0500 Subject: [PATCH] fix: clean the remaining std::error::Error --- CONTRIBUTING.md | 2 +- opentelemetry-jaeger/src/lib.rs | 62 +++++++++++++------------- opentelemetry-otlp/src/proto/common.rs | 4 +- opentelemetry-zipkin/src/lib.rs | 38 ++++++++-------- 4 files changed, 53 insertions(+), 53 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 6fc6e4144a..d63c98f1d3 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -96,7 +96,7 @@ https://github.com/open-telemetry/opentelemetry-specification/issues/165 ### Error Handling Currently, the Opentelemetry Rust SDK has two ways to handle errors. In the situation where errors are not allowed to return. One should call global error handler to process the errors. Otherwise, one should return the errors. -The Opentelemetry Rust SDK comes with an error type `openetelemetry::Error`. For different function, one error has been defined. All error returned by trace module MUST be wrapped in `opentelemetry::api::trace::TraceError`. All errors returned by metrics module MUST be wrapped in `opentelemetry::api::trace::MetricsError`. +The Opentelemetry Rust SDK comes with an error type `openetelemetry::Error`. For different function, one error has been defined. All error returned by trace module MUST be wrapped in `opentelemetry::trace::TraceError`. All errors returned by metrics module MUST be wrapped in `opentelemetry::metrics::MetricsError`. For users that want to implement their own exporters. It's RECOMMENDED to wrap all errors from the exporter into a crate-level error type, and implement `ExporterError` trait. diff --git a/opentelemetry-jaeger/src/lib.rs b/opentelemetry-jaeger/src/lib.rs index 25209fa6cf..fdbd0dfadf 100644 --- a/opentelemetry-jaeger/src/lib.rs +++ b/opentelemetry-jaeger/src/lib.rs @@ -22,7 +22,7 @@ //! ```no_run //! use opentelemetry::trace::Tracer; //! -//! fn main() -> Result<(), Box> { +//! fn main() -> Result<(), opentelemetry::trace::TraceError> { //! let (tracer, _uninstall) = opentelemetry_jaeger::new_pipeline().install()?; //! //! tracer.in_span("doing_work", |cx| { @@ -59,9 +59,9 @@ //! [jaeger variables spec]: https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/sdk-environment-variables.md#jaeger-exporter //! //! ```no_run -//! use opentelemetry::trace::Tracer; +//! use opentelemetry::trace::{Tracer, TraceError}; //! -//! fn main() -> Result<(), Box> { +//! fn main() -> Result<(), TraceError> { //! // export OTEL_SERVICE_NAME=my-service-name //! let (tracer, _uninstall) = opentelemetry_jaeger::new_pipeline().from_env().install()?; //! @@ -90,9 +90,9 @@ //! //! ```ignore //! // Note that this requires the `collector_client` feature. -//! use opentelemetry::trace::Tracer; +//! use opentelemetry::trace::{Tracer, TraceError}; //! -//! fn main() -> Result<(), Box> { +//! fn main() -> Result<(), TraceError> { //! let (tracer, _uninstall) = opentelemetry_jaeger::new_pipeline() //! .with_collector_endpoint("http://localhost:14268/api/traces") //! // optionally set username and password as well. @@ -116,10 +116,10 @@ //! [`PipelineBuilder`]: struct.PipelineBuilder.html //! //! ```no_run -//! use opentelemetry::{KeyValue, trace::Tracer}; +//! use opentelemetry::{KeyValue, trace::{Tracer, TraceError}}; //! use opentelemetry::sdk::{trace::{self, IdGenerator, Sampler}, Resource}; //! -//! fn main() -> Result<(), Box> { +//! fn main() -> Result<(), TraceError> { //! let (tracer, _uninstall) = opentelemetry_jaeger::new_pipeline() //! .from_env() //! .with_agent_endpoint("localhost:6831") @@ -165,17 +165,17 @@ //! supported compiler version is not considered a semver breaking change as //! long as doing so complies with this policy. #![warn( - future_incompatible, - missing_debug_implementations, - missing_docs, - nonstandard_style, - rust_2018_idioms, - unreachable_pub, - unused +future_incompatible, +missing_debug_implementations, +missing_docs, +nonstandard_style, +rust_2018_idioms, +unreachable_pub, +unused )] #![cfg_attr(docsrs, feature(doc_cfg), deny(broken_intra_doc_links))] #![doc( - html_logo_url = "https://raw.githubusercontent.com/open-telemetry/opentelemetry-rust/master/assets/logo.svg" +html_logo_url = "https://raw.githubusercontent.com/open-telemetry/opentelemetry-rust/master/assets/logo.svg" )] #![cfg_attr(test, deny(warnings))] @@ -357,12 +357,12 @@ impl PipelineBuilder { /// E.g. "http://localhost:14268/api/traces" #[cfg(any(feature = "collector_client", feature = "wasm_collector_client"))] #[cfg_attr( - docsrs, - doc(cfg(any(feature = "collector_client", feature = "wasm_collector_client"))) + docsrs, + doc(cfg(any(feature = "collector_client", feature = "wasm_collector_client"))) )] pub fn with_collector_endpoint(self, collector_endpoint: T) -> Self - where - http::Uri: core::convert::TryFrom, + where + http::Uri: core::convert::TryFrom, { PipelineBuilder { collector_endpoint: core::convert::TryFrom::try_from(collector_endpoint).ok(), @@ -373,8 +373,8 @@ impl PipelineBuilder { /// Assign the collector username #[cfg(any(feature = "collector_client", feature = "wasm_collector_client"))] #[cfg_attr( - docsrs, - doc(any(feature = "collector_client", feature = "wasm_collector_client")) + docsrs, + doc(any(feature = "collector_client", feature = "wasm_collector_client")) )] pub fn with_collector_username>(self, collector_username: S) -> Self { PipelineBuilder { @@ -386,8 +386,8 @@ impl PipelineBuilder { /// Assign the collector password #[cfg(any(feature = "collector_client", feature = "wasm_collector_client"))] #[cfg_attr( - docsrs, - doc(any(feature = "collector_client", feature = "wasm_collector_client")) + docsrs, + doc(any(feature = "collector_client", feature = "wasm_collector_client")) )] pub fn with_collector_password>(self, collector_password: S) -> Self { PipelineBuilder { @@ -403,7 +403,7 @@ impl PipelineBuilder { } /// Assign the process service tags. - pub fn with_tags>(mut self, tags: T) -> Self { + pub fn with_tags>(mut self, tags: T) -> Self { self.process.tags = tags.into_iter().collect(); self } @@ -446,7 +446,7 @@ impl PipelineBuilder { /// This is useful if you are manually constructing a pipeline. pub fn init_exporter( self, - ) -> Result> { + ) -> Result { let export_instrumentation_lib = self.export_instrument_library; let (process, uploader) = self.init_uploader()?; @@ -460,8 +460,8 @@ impl PipelineBuilder { #[cfg(not(any(feature = "collector_client", feature = "wasm_collector_client")))] fn init_uploader( self, - ) -> Result<(Process, BatchUploader), Box> { - let agent = AgentAsyncClientUDP::new(self.agent_endpoint.as_slice())?; + ) -> Result<(Process, BatchUploader), TraceError> { + let agent = AgentAsyncClientUDP::new(self.agent_endpoint.as_slice()).map_err::(Into::into)?; Ok((self.process, BatchUploader::Agent(agent))) } @@ -470,18 +470,18 @@ impl PipelineBuilder { self, ) -> Result< (Process, uploader::BatchUploader), - Box, + TraceError, > { if let Some(collector_endpoint) = self.collector_endpoint { let collector = CollectorAsyncClientHttp::new( collector_endpoint, self.collector_username, self.collector_password, - )?; + ).map_err::(Into::into)?; Ok((self.process, uploader::BatchUploader::Collector(collector))) } else { let endpoint = self.agent_endpoint.as_slice(); - let agent = AgentAsyncClientUDP::new(endpoint)?; + let agent = AgentAsyncClientUDP::new(endpoint).map_err::(Into::into)?; Ok((self.process, BatchUploader::Agent(agent))) } } @@ -598,7 +598,7 @@ fn convert_otel_span_into_jaeger_span( fn build_process_tags( span_data: &trace::SpanData, -) -> Option + '_> { +) -> Option + '_> { if span_data.resource.is_empty() { None } else { diff --git a/opentelemetry-otlp/src/proto/common.rs b/opentelemetry-otlp/src/proto/common.rs index 8ce33f65f2..0b5074e6f1 100644 --- a/opentelemetry-otlp/src/proto/common.rs +++ b/opentelemetry-otlp/src/proto/common.rs @@ -1,4 +1,4 @@ -// This file is generated by rust-protobuf 2.18.0. Do not edit +// This file is generated by rust-protobuf 2.18.1. Do not edit // @generated // https://github.com/rust-lang/rust-clippy/issues/702 @@ -21,7 +21,7 @@ /// Generated files are compatible only with the same version /// of protobuf runtime. -// const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_2_18_0; +// const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_2_18_1; #[derive(PartialEq,Clone,Default)] #[cfg_attr(feature = "with-serde", derive(Serialize, Deserialize))] diff --git a/opentelemetry-zipkin/src/lib.rs b/opentelemetry-zipkin/src/lib.rs index 0459ee450d..5db29622bd 100644 --- a/opentelemetry-zipkin/src/lib.rs +++ b/opentelemetry-zipkin/src/lib.rs @@ -21,9 +21,9 @@ //! telemetry: //! //! ```no_run -//! use opentelemetry::trace::Tracer; +//! use opentelemetry::trace::{Tracer, TraceError}; //! -//! fn main() -> Result<(), Box> { +//! fn main() -> Result<(), TraceError> { //! let (tracer, _uninstall) = opentelemetry_zipkin::new_pipeline().install()?; //! //! tracer.in_span("doing_work", |cx| { @@ -148,17 +148,17 @@ //! supported compiler version is not considered a semver breaking change as //! long as doing so complies with this policy. #![warn( - future_incompatible, - missing_debug_implementations, - missing_docs, - nonstandard_style, - rust_2018_idioms, - unreachable_pub, - unused +future_incompatible, +missing_debug_implementations, +missing_docs, +nonstandard_style, +rust_2018_idioms, +unreachable_pub, +unused )] #![cfg_attr(docsrs, feature(doc_cfg), deny(broken_intra_doc_links))] #![doc( - html_logo_url = "https://raw.githubusercontent.com/open-telemetry/opentelemetry-rust/master/assets/logo.svg" +html_logo_url = "https://raw.githubusercontent.com/open-telemetry/opentelemetry-rust/master/assets/logo.svg" )] #![cfg_attr(test, deny(warnings))] @@ -224,21 +224,21 @@ impl Default for ZipkinPipelineBuilder { #[cfg(feature = "reqwest-blocking-client")] client: Some(Box::new(reqwest::blocking::Client::new())), #[cfg(all( - not(feature = "reqwest-blocking-client"), - not(feature = "surf-client"), - feature = "reqwest-client" + not(feature = "reqwest-blocking-client"), + not(feature = "surf-client"), + feature = "reqwest-client" ))] client: Some(Box::new(reqwest::Client::new())), #[cfg(all( - not(feature = "reqwest-client"), - not(feature = "reqwest-blocking-client"), - feature = "surf-client" + not(feature = "reqwest-client"), + not(feature = "reqwest-blocking-client"), + feature = "surf-client" ))] client: Some(Box::new(surf::Client::new())), #[cfg(all( - not(feature = "reqwest-client"), - not(feature = "surf-client"), - not(feature = "reqwest-blocking-client") + not(feature = "reqwest-client"), + not(feature = "surf-client"), + not(feature = "reqwest-blocking-client") ))] client: None,