diff --git a/CHANGELOG.md b/CHANGELOG.md index 56eff7e..b68ed13 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ### Added - `default-tls`, `rustls-native`, and `rustls-webpki` features to allow usage of rustls for the https client ### Changed +- `opentelemetry` feature must be specified to enable opentelemetry support. +- `opentelemetry` updated to version `0.18`. +- `base64` updated to version `0.20`. ### Deprecated ### Removed ### Fixed diff --git a/Cargo.toml b/Cargo.toml index bfa27c6..0b24af8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,17 +15,18 @@ default-tls = ["hyper-tls"] metrics = ["prometheus", "lazy_static"] rustls-native = ["hyper-rustls/rustls-native-certs"] rustls-webpki = ["hyper-rustls/webpki-roots"] +opentelemetry = ["dep:opentelemetry"] # keep this list sorted! [dependencies] -base64 = "0.13.0" +base64 = "0.20.0" futures = "0.3.8" http = "0.2.1" hyper = { version = "0.14.2", features = ["full"] } hyper-rustls = { version = "0.22.1", optional = true } -hyper-tls = { version = "0.5.0", optional = true, no-default-features = true } +hyper-tls = { version = "0.5.0", optional = true, default-features = true } lazy_static = { version = "1.4.0", optional = true } -opentelemetry = { version = "0.15", features = ["tokio", "rt-tokio"] } +opentelemetry = { version = "0.18", features = ["rt-tokio"], optional = true } prometheus = { version = "0.13", optional = true } quick-error = "2.0" serde = { version = "1.0", features = ["derive"] } diff --git a/src/hyper_wrapper.rs b/src/hyper_wrapper.rs index 65b5041..e38ff54 100644 --- a/src/hyper_wrapper.rs +++ b/src/hyper_wrapper.rs @@ -25,7 +25,7 @@ SOFTWARE. use hyper::Version; use opentelemetry::{ global::{BoxedSpan, BoxedTracer}, - trace::{Span, StatusCode, Tracer}, + trace::{Span, Status, Tracer}, KeyValue, }; @@ -84,6 +84,6 @@ pub fn annotate_span_for_response(span: &mut BoxedSpan, response: &hyper::Res } if status != hyper::StatusCode::OK { - span.set_status(StatusCode::Error, status.as_str().to_owned()); + span.set_status(Status::error(status.as_str().to_owned())); } } diff --git a/src/lib.rs b/src/lib.rs index 2540c82..daacda5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -39,17 +39,23 @@ use hyper_tls::HttpsConnector; #[cfg(feature = "metrics")] use lazy_static::lazy_static; -use opentelemetry::global; -use opentelemetry::global::BoxedTracer; -use opentelemetry::trace::Span; -use opentelemetry::trace::StatusCode; use quick_error::quick_error; use serde::{Deserialize, Serialize}; use slog_scope::{error, info}; use tokio::time::timeout; +#[cfg(feature="opentelemetry")] +use opentelemetry::global; +#[cfg(feature="opentelemetry")] +use opentelemetry::global::BoxedTracer; +#[cfg(feature="opentelemetry")] +use opentelemetry::trace::Span; +#[cfg(feature="opentelemetry")] +use opentelemetry::trace::Status; + pub use types::*; +#[cfg(feature="opentelemetry")] mod hyper_wrapper; /// The strongly typed data structures representing canonical consul objects. pub mod types; @@ -214,6 +220,7 @@ impl Drop for Lock<'_> { pub struct Consul { https_client: hyper::Client, Body>, config: Config, + #[cfg(feature="opentelemetry")] tracer: BoxedTracer, } @@ -237,6 +244,7 @@ impl Consul { Consul { https_client, config, + #[cfg(feature="opentelemetry")] tracer: global::tracer("consul"), } } @@ -671,6 +679,7 @@ impl Consul { ) .body(body); let req = req.map_err(ConsulError::RequestError)?; + #[cfg(feature="opentelemetry")] let mut span = crate::hyper_wrapper::span_for_request(&self.tracer, &req); let method = req.method().clone(); @@ -698,6 +707,7 @@ impl Consul { let response = response?; + #[cfg(feature="opentelemetry")] crate::hyper_wrapper::annotate_span_for_response(&mut span, &response); let status = response.status(); @@ -725,7 +735,8 @@ impl Consul { Err(e) => { record_failure_metric_if_enabled(&method, request_name); - span.set_status(StatusCode::Error, e.to_string()); + #[cfg(feature="opentelemetry")] + span.set_status(Status::error(e.to_string())); Err(ConsulError::InvalidResponse(e)) } }