Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions opentelemetry-jaeger/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-zipkin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 1 addition & 4 deletions src/api/context/propagation/composite_propagator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
80 changes: 54 additions & 26 deletions src/api/trace/b3_propagator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -82,8 +82,7 @@ impl B3Propagator {
/// Extract trace id from hex encoded &str value.
fn extract_trace_id(&self, trace_id: &str) -> Result<api::TraceId, ()> {
// 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)
Expand Down Expand Up @@ -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,
Expand All @@ -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())
}
}
Expand All @@ -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()))
Expand All @@ -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![
Expand Down Expand Up @@ -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<String, String> {
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<String, String> {
let mut carrier = HashMap::new();
if let Some(trace_id) = trace {
carrier.insert(B3_TRACE_ID_HEADER.to_string(), trace_id.to_owned());
Expand Down Expand Up @@ -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!(
Expand All @@ -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)
Expand Down Expand Up @@ -511,7 +521,8 @@ mod tests {
_name: String,
_timestamp: std::time::SystemTime,
_attributes: Vec<api::KeyValue>,
) {}
) {
}
fn span_context(&self) -> api::SpanContext {
self.0.clone()
}
Expand All @@ -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() {
Expand Down Expand Up @@ -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);
Expand All @@ -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())
Expand Down
13 changes: 5 additions & 8 deletions src/api/trace/span.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down
1 change: 0 additions & 1 deletion src/api/trace/span_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down