Skip to content

Commit

Permalink
fix: clean the remaining std::error::Error
Browse files Browse the repository at this point in the history
  • Loading branch information
TommyCpp committed Nov 29, 2020
1 parent 1d1f656 commit ebc902b
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 53 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Expand Up @@ -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.

Expand Down
62 changes: 31 additions & 31 deletions opentelemetry-jaeger/src/lib.rs
Expand Up @@ -22,7 +22,7 @@
//! ```no_run
//! use opentelemetry::trace::Tracer;
//!
//! fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
//! fn main() -> Result<(), opentelemetry::trace::TraceError> {
//! let (tracer, _uninstall) = opentelemetry_jaeger::new_pipeline().install()?;
//!
//! tracer.in_span("doing_work", |cx| {
Expand Down Expand Up @@ -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<dyn std::error::Error + Send + Sync + 'static>> {
//! fn main() -> Result<(), TraceError> {
//! // export OTEL_SERVICE_NAME=my-service-name
//! let (tracer, _uninstall) = opentelemetry_jaeger::new_pipeline().from_env().install()?;
//!
Expand Down Expand Up @@ -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<dyn std::error::Error + Send + Sync + 'static>> {
//! 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.
Expand All @@ -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<dyn std::error::Error + Send + Sync + 'static>> {
//! fn main() -> Result<(), TraceError> {
//! let (tracer, _uninstall) = opentelemetry_jaeger::new_pipeline()
//! .from_env()
//! .with_agent_endpoint("localhost:6831")
Expand Down Expand Up @@ -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))]

Expand Down Expand Up @@ -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<T>(self, collector_endpoint: T) -> Self
where
http::Uri: core::convert::TryFrom<T>,
where
http::Uri: core::convert::TryFrom<T>,
{
PipelineBuilder {
collector_endpoint: core::convert::TryFrom::try_from(collector_endpoint).ok(),
Expand All @@ -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<S: Into<String>>(self, collector_username: S) -> Self {
PipelineBuilder {
Expand All @@ -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<S: Into<String>>(self, collector_password: S) -> Self {
PipelineBuilder {
Expand All @@ -403,7 +403,7 @@ impl PipelineBuilder {
}

/// Assign the process service tags.
pub fn with_tags<T: IntoIterator<Item = KeyValue>>(mut self, tags: T) -> Self {
pub fn with_tags<T: IntoIterator<Item=KeyValue>>(mut self, tags: T) -> Self {
self.process.tags = tags.into_iter().collect();
self
}
Expand Down Expand Up @@ -446,7 +446,7 @@ impl PipelineBuilder {
/// This is useful if you are manually constructing a pipeline.
pub fn init_exporter(
self,
) -> Result<Exporter, Box<dyn std::error::Error + Send + Sync + 'static>> {
) -> Result<Exporter, TraceError> {
let export_instrumentation_lib = self.export_instrument_library;
let (process, uploader) = self.init_uploader()?;

Expand All @@ -460,8 +460,8 @@ impl PipelineBuilder {
#[cfg(not(any(feature = "collector_client", feature = "wasm_collector_client")))]
fn init_uploader(
self,
) -> Result<(Process, BatchUploader), Box<dyn std::error::Error + Send + Sync + 'static>> {
let agent = AgentAsyncClientUDP::new(self.agent_endpoint.as_slice())?;
) -> Result<(Process, BatchUploader), TraceError> {
let agent = AgentAsyncClientUDP::new(self.agent_endpoint.as_slice()).map_err::<Error, _>(Into::into)?;
Ok((self.process, BatchUploader::Agent(agent)))
}

Expand All @@ -470,18 +470,18 @@ impl PipelineBuilder {
self,
) -> Result<
(Process, uploader::BatchUploader),
Box<dyn std::error::Error + Send + Sync + 'static>,
TraceError,
> {
if let Some(collector_endpoint) = self.collector_endpoint {
let collector = CollectorAsyncClientHttp::new(
collector_endpoint,
self.collector_username,
self.collector_password,
)?;
).map_err::<Error, _>(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::<Error, _>(Into::into)?;
Ok((self.process, BatchUploader::Agent(agent)))
}
}
Expand Down Expand Up @@ -598,7 +598,7 @@ fn convert_otel_span_into_jaeger_span(

fn build_process_tags(
span_data: &trace::SpanData,
) -> Option<impl Iterator<Item = jaeger::Tag> + '_> {
) -> Option<impl Iterator<Item=jaeger::Tag> + '_> {
if span_data.resource.is_empty() {
None
} else {
Expand Down
4 changes: 2 additions & 2 deletions 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
Expand All @@ -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))]
Expand Down
38 changes: 19 additions & 19 deletions opentelemetry-zipkin/src/lib.rs
Expand Up @@ -21,9 +21,9 @@
//! telemetry:
//!
//! ```no_run
//! use opentelemetry::trace::Tracer;
//! use opentelemetry::trace::{Tracer, TraceError};
//!
//! fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
//! fn main() -> Result<(), TraceError> {
//! let (tracer, _uninstall) = opentelemetry_zipkin::new_pipeline().install()?;
//!
//! tracer.in_span("doing_work", |cx| {
Expand Down Expand Up @@ -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))]

Expand Down Expand Up @@ -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,

Expand Down

0 comments on commit ebc902b

Please sign in to comment.