Skip to content

Commit

Permalink
fix: allow span id to be less than 16 characters in jaeger propagator (
Browse files Browse the repository at this point in the history
  • Loading branch information
TommyCpp authored Jun 1, 2023
1 parent e804992 commit 800b9e3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
4 changes: 4 additions & 0 deletions opentelemetry-jaeger/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# Changelog
## Main
### Fixed
- allow span id to be less than 16 characters in propagator [#1084](https://github.com/open-telemetry/opentelemetry-rust/pull/1084)

## v0.18.0

### Added
Expand Down
27 changes: 23 additions & 4 deletions opentelemetry-jaeger/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -484,11 +484,17 @@ mod propagator {

/// Extract span id from the header.
fn extract_span_id(&self, span_id: &str) -> Result<SpanId, ()> {
if span_id.len() != 16 {
return Err(());
match span_id.len() {
// exact 16
16 => SpanId::from_hex(span_id).map_err(|_| ()),
// more than 16 is invalid
17.. => Err(()),
// less than 16 will result padding on left
_ => {
let padded = format!("{span_id:0>16}");
SpanId::from_hex(&padded).map_err(|_| ())
}
}

SpanId::from_hex(span_id).map_err(|_| ())
}

/// Extract flag from the header
Expand Down Expand Up @@ -589,6 +595,7 @@ mod propagator {
const SHORT_TRACE_ID_STR: &str = "4d0000000000000016";
const TRACE_ID: u128 = 0x0000_0000_0000_004d_0000_0000_0000_0016;
const SPAN_ID_STR: &str = "0000000000017c29";
const SHORT_SPAN_ID_STR: &str = "17c29";
const SPAN_ID: u64 = 0x0000_0000_0001_7c29;

fn get_extract_data() -> Vec<(&'static str, &'static str, u8, SpanContext)> {
Expand Down Expand Up @@ -617,6 +624,18 @@ mod propagator {
TraceState::default(),
),
),
(
SHORT_TRACE_ID_STR,
SHORT_SPAN_ID_STR,
1,
SpanContext::new(
TraceId::from_u128(TRACE_ID),
SpanId::from_u64(SPAN_ID),
TraceFlags::SAMPLED,
true,
TraceState::default(),
),
),
(
LONG_TRACE_ID_STR,
SPAN_ID_STR,
Expand Down

0 comments on commit 800b9e3

Please sign in to comment.