diff --git a/opentelemetry-jaeger/src/lib.rs b/opentelemetry-jaeger/src/lib.rs index 09e3e034d5..b04259ef0c 100644 --- a/opentelemetry-jaeger/src/lib.rs +++ b/opentelemetry-jaeger/src/lib.rs @@ -97,6 +97,7 @@ mod agent; #[cfg(feature = "collector_client")] mod collector; #[allow(clippy::all, unreachable_pub, dead_code)] +#[rustfmt::skip] mod thrift; pub(crate) mod transport; mod uploader; diff --git a/opentelemetry-zipkin/src/lib.rs b/opentelemetry-zipkin/src/lib.rs index 45c22791e1..c7ae985856 100644 --- a/opentelemetry-zipkin/src/lib.rs +++ b/opentelemetry-zipkin/src/lib.rs @@ -143,7 +143,7 @@ impl ExporterConfigBuilder { self.service_endpoint = Some(endpoint); self } - + /// Assign the collector endpoint for `ConfigBuilder` pub fn with_collector_endpoint(&mut self, endpoint: String) -> &mut Self { self.collector_endpoint = Some(endpoint); diff --git a/src/api/context/propagation/composite_propagator.rs b/src/api/context/propagation/composite_propagator.rs index 14646d2588..bb5e6394d4 100644 --- a/src/api/context/propagation/composite_propagator.rs +++ b/src/api/context/propagation/composite_propagator.rs @@ -88,10 +88,7 @@ mod tests { fn test_data() -> Vec<(&'static str, &'static str)> { vec![ - ( - "b3", - "00000000000000000000000000000001-0000000000000001-0", - ), + ("b3", "00000000000000000000000000000001-0000000000000001-0"), ( "traceparent", "00-00000000000000000000000000000001-0000000000000001-00", diff --git a/src/api/mod.rs b/src/api/mod.rs index 5cb45ceb88..23f6ee9df8 100644 --- a/src/api/mod.rs +++ b/src/api/mod.rs @@ -48,7 +48,8 @@ pub use trace::{ sampler::{Sampler, SamplingDecision, SamplingResult}, span::{Span, SpanKind, StatusCode}, span_context::{ - SpanContext, SpanId, TraceId, TRACE_FLAG_DEBUG, TRACE_FLAG_DEFERRED, TRACE_FLAG_SAMPLED, TRACE_FLAG_NOT_SAMPLED + SpanContext, SpanId, TraceId, TRACE_FLAG_DEBUG, TRACE_FLAG_DEFERRED, + TRACE_FLAG_NOT_SAMPLED, TRACE_FLAG_SAMPLED, }, span_processor::SpanProcessor, trace_context_propagator::TraceContextPropagator, diff --git a/src/api/trace/b3_propagator.rs b/src/api/trace/b3_propagator.rs index cee2e67be9..91b71a596e 100644 --- a/src/api/trace/b3_propagator.rs +++ b/src/api/trace/b3_propagator.rs @@ -13,9 +13,9 @@ //! //! If `inject_encoding` is set to `B3Encoding::SingleHeader` then `b3` header is used to inject //! and extract. Otherwise, separate headers are used to inject and extract. -use crate::{api, api::TraceContextExt}; -use crate::api::TRACE_FLAG_DEFERRED; use crate::api::trace::b3_propagator::B3Encoding::MultipleHeader; +use crate::api::TRACE_FLAG_DEFERRED; +use crate::{api, api::TraceContextExt}; static B3_SINGLE_HEADER: &str = "b3"; /// As per spec, the multiple header should be case sensitive. But different protocol will use @@ -82,8 +82,7 @@ impl B3Propagator { /// Extract trace id from hex encoded &str value. fn extract_trace_id(&self, trace_id: &str) -> Result { // Only allow lower case hex string - if trace_id.to_lowercase() != trace_id || - (trace_id.len() != 16 && trace_id.len() != 32) { + if trace_id.to_lowercase() != trace_id || (trace_id.len() != 16 && trace_id.len() != 32) { Err(()) } else { u128::from_str_radix(trace_id, 16) @@ -223,8 +222,9 @@ impl api::HttpTextFormat for B3Propagator { carrier.set(B3_SINGLE_HEADER, value); } - if self.inject_encoding.support(&B3Encoding::MultipleHeader) || - self.inject_encoding.support(&B3Encoding::UnSpecified) { + if self.inject_encoding.support(&B3Encoding::MultipleHeader) + || self.inject_encoding.support(&B3Encoding::UnSpecified) + { // if inject_encoding is Unspecified, default to use MultipleHeader carrier.set( B3_TRACE_ID_HEADER, @@ -247,8 +247,9 @@ impl api::HttpTextFormat for B3Propagator { if self.inject_encoding.support(&B3Encoding::SingleHeader) { carrier.set(B3_SINGLE_HEADER, flag.to_string()) } - if self.inject_encoding.support(&B3Encoding::MultipleHeader) || - self.inject_encoding.support(&B3Encoding::UnSpecified) { + if self.inject_encoding.support(&B3Encoding::MultipleHeader) + || self.inject_encoding.support(&B3Encoding::UnSpecified) + { carrier.set(B3_SAMPLED_HEADER, flag.to_string()) } } @@ -259,8 +260,7 @@ impl api::HttpTextFormat for B3Propagator { /// `Context` is returned. fn extract_with_context(&self, cx: &api::Context, carrier: &dyn api::Carrier) -> api::Context { let span_context = if self.inject_encoding.support(&B3Encoding::SingleHeader) { - self.extract_single_header(carrier) - .unwrap_or_else(|_| + self.extract_single_header(carrier).unwrap_or_else(|_| // if invalid single header should fallback to multiple self.extract_multi_header(carrier) .unwrap_or_else(|_| api::SpanContext::empty_context())) @@ -285,7 +285,6 @@ mod tests { const TRACE_ID_HEX: u128 = 0x4bf9_2f35_77b3_4da6_a3ce_929d_0e0e_4736; const SPAN_ID_HEX: u64 = 0x00f0_67aa_0ba9_02b7; - #[rustfmt::skip] fn single_header_extract_data() -> Vec<(&'static str, api::SpanContext)> { vec![ @@ -407,7 +406,13 @@ mod tests { ] } - fn extract_carrier_from_test_data(trace: Option<&'static str>, span: Option<&'static str>, sampled: Option<&'static str>, debug: Option<&'static str>, parent: Option<&'static str>) -> HashMap { + fn extract_carrier_from_test_data( + trace: Option<&'static str>, + span: Option<&'static str>, + sampled: Option<&'static str>, + debug: Option<&'static str>, + parent: Option<&'static str>, + ) -> HashMap { let mut carrier = HashMap::new(); if let Some(trace_id) = trace { carrier.insert(B3_TRACE_ID_HEADER.to_string(), trace_id.to_owned()); @@ -462,7 +467,9 @@ mod tests { ) } - for ((trace, span, sampled, debug, parent), single_header, expected_context) in single_multi_header_extract_data() { + for ((trace, span, sampled, debug, parent), single_header, expected_context) in + single_multi_header_extract_data() + { let mut carrier = extract_carrier_from_test_data(trace, span, sampled, debug, parent); carrier.insert(B3_SINGLE_HEADER.to_string(), single_header.to_owned()); assert_eq!( @@ -481,7 +488,10 @@ mod tests { for invalid_single_header in single_header_extrace_invalid_data() { let mut carrier = HashMap::new(); - carrier.insert(B3_SINGLE_HEADER.to_string(), invalid_single_header.to_string()); + carrier.insert( + B3_SINGLE_HEADER.to_string(), + invalid_single_header.to_string(), + ); assert_eq!( single_header_propagator .extract(&carrier) @@ -511,7 +521,8 @@ mod tests { _name: String, _timestamp: std::time::SystemTime, _attributes: Vec, - ) {} + ) { + } fn span_context(&self) -> api::SpanContext { self.0.clone() } @@ -528,7 +539,8 @@ mod tests { fn inject_b3() { let single_header_propagator = B3Propagator::with_encoding(B3Encoding::SingleHeader); let multi_header_propagator = B3Propagator::with_encoding(B3Encoding::MultipleHeader); - let single_multi_header_propagator = B3Propagator::with_encoding(B3Encoding::SingleAndMultiHeader); + let single_multi_header_propagator = + B3Propagator::with_encoding(B3Encoding::SingleAndMultiHeader); let unspecified_header_propagator = B3Propagator::with_encoding(B3Encoding::UnSpecified); for (expected_header, context) in single_header_inject_data() { @@ -558,16 +570,28 @@ mod tests { assert_eq!(carrier_multi_header, carrier_unspecific); - assert_eq!(carrier_multi_header.get(B3_TRACE_ID_HEADER).map(|s| s.to_owned()), - trace_id.map(|s| s.to_string())); - assert_eq!(carrier_multi_header.get(B3_SPAN_ID_HEADER).map(|s| s.to_owned()), - span_id.map(|s| s.to_string())); assert_eq!( - carrier_multi_header.get(B3_SAMPLED_HEADER).map(|s| s.to_owned()), + carrier_multi_header + .get(B3_TRACE_ID_HEADER) + .map(|s| s.to_owned()), + trace_id.map(|s| s.to_string()) + ); + assert_eq!( + carrier_multi_header + .get(B3_SPAN_ID_HEADER) + .map(|s| s.to_owned()), + span_id.map(|s| s.to_string()) + ); + assert_eq!( + carrier_multi_header + .get(B3_SAMPLED_HEADER) + .map(|s| s.to_owned()), sampled.map(|s| s.to_string()) ); assert_eq!( - carrier_multi_header.get(B3_DEBUG_FLAG_HEADER).map(|s| s.to_owned()), + carrier_multi_header + .get(B3_DEBUG_FLAG_HEADER) + .map(|s| s.to_owned()), flag.map(|s| s.to_string()) ); assert_eq!(carrier_multi_header.get(B3_PARENT_SPAN_ID_HEADER), None); @@ -580,10 +604,14 @@ mod tests { &mut carrier, ); - assert_eq!(carrier.get(B3_TRACE_ID_HEADER).map(|s| s.to_owned()), - trace_id.map(|s| s.to_string())); - assert_eq!(carrier.get(B3_SPAN_ID_HEADER).map(|s| s.to_owned()), - span_id.map(|s| s.to_string())); + assert_eq!( + carrier.get(B3_TRACE_ID_HEADER).map(|s| s.to_owned()), + trace_id.map(|s| s.to_string()) + ); + assert_eq!( + carrier.get(B3_SPAN_ID_HEADER).map(|s| s.to_owned()), + span_id.map(|s| s.to_string()) + ); assert_eq!( carrier.get(B3_SAMPLED_HEADER).map(|s| s.to_owned()), sampled.map(|s| s.to_string()) diff --git a/src/api/trace/span.rs b/src/api/trace/span.rs index cf36a4a1cb..ece753089c 100644 --- a/src/api/trace/span.rs +++ b/src/api/trace/span.rs @@ -53,10 +53,7 @@ pub trait Span: fmt::Debug + 'static + Send + Sync { /// Users can custom the exception message by overriding the `fmt::Display` trait's `fmt` method /// for the error. fn record_exception(&self, err: &dyn Error) { - let attributes = vec![api::KeyValue::new( - "exception.message", - err.to_string(), - )]; + let attributes = vec![api::KeyValue::new("exception.message", err.to_string())]; self.add_event("exception".to_string(), attributes); } @@ -65,10 +62,10 @@ pub trait Span: fmt::Debug + 'static + Send + Sync { /// /// See `Span:record_exception` method for more details. fn record_exception_with_stacktrace(&self, err: &dyn Error, stacktrace: String) { - let attributes = vec![api::KeyValue::new( - "exception.message", - err.to_string(), - ), api::KeyValue::new("exception.stacktrace", stacktrace)]; + let attributes = vec![ + api::KeyValue::new("exception.message", err.to_string()), + api::KeyValue::new("exception.stacktrace", stacktrace), + ]; self.add_event("exception".to_string(), attributes); } diff --git a/src/api/trace/span_context.rs b/src/api/trace/span_context.rs index 41b16acd8c..b6ec6c393f 100644 --- a/src/api/trace/span_context.rs +++ b/src/api/trace/span_context.rs @@ -13,7 +13,6 @@ #[cfg(feature = "serialize")] use serde::{Deserialize, Serialize}; - /// A SpanContext with TRACE_FLAG_NOT_SAMPLED means the span is not sampled. pub const TRACE_FLAG_NOT_SAMPLED: u8 = 0x00; /// TRACE_FLAG_SAMPLED is a bitmask with the sampled bit set. A SpanContext