diff --git a/bin/correctness/otlp-fixtures/src/traces/conversion.rs b/bin/correctness/otlp-fixtures/src/traces/conversion.rs index 1297d11a0ee..29f7e46d191 100644 --- a/bin/correctness/otlp-fixtures/src/traces/conversion.rs +++ b/bin/correctness/otlp-fixtures/src/traces/conversion.rs @@ -566,8 +566,10 @@ fn kind_traces() -> Vec> { /// The traces whose spans have trace IDs that share their low half. /// -/// A trace groups spans by the low half of their ID. The two spans of the first and second traces have the same low -/// half and different high halves, and the spans of the third trace have the same ID. +/// The low half of a trace ID identifies the trace, and a zero high half is absent, so spans that share a low half stay +/// together. The two spans of the first trace have different non-zero high halves, those of the second have a zero and +/// a non-zero high half, and those of the third have the same ID. Both sides keep every span of these traces, and the +/// case pairs the spans on their span ID and the low half of the trace ID. fn high_traces() -> Vec> { let span = |name| ProbeSpan::new(HIGH_SERVICE, name, SpanKind::Internal); vec![ diff --git a/docs/development/panoramic.md b/docs/development/panoramic.md index bc9fb37dc01..84d02e4e39d 100644 --- a/docs/development/panoramic.md +++ b/docs/development/panoramic.md @@ -1161,11 +1161,12 @@ their difference as a defect. ### When only one intake receives a span Use `span.` if the spans pair and one field differs. Use `paths: [spans]` only if an open gap explains why -the entire span is on one side. For example, the Agent keeps `otlpprobe.conv.high.mixed_a` in the trace conversion -case, but ADP drops it. There is no ADP span whose fields `compare` could check. +the entire span is on one side. For example, the Agent keeps the second `feat.rare.status` trace in the trace +obfuscation features case, but the rare sampler of ADP drops it. There is no ADP span whose fields `compare` could +check. -The entry for [this gap](https://github.com/DataDog/saluki/issues/3445) sets `kinds: [missing]` and lists the affected -resources in `when`. Use `extra` for a span only ADP sends. A whole-span entry must set `kinds` to `[missing]` or +The entry for [this gap](https://github.com/DataDog/saluki/issues/3578) sets `kinds: [missing]` and lists the affected +span names in `when`. Use `extra` for a span only ADP sends. A whole-span entry must set `kinds` to `[missing]` or `[extra]` and select by `name` or `resource`; `service` alone is too broad. Panoramic matches `when` against the span on the side that has it. If ADP sends the span too, the `missing` path goes stale for that resource and `compare` checks the paired spans. diff --git a/lib/saluki-components/src/common/otlp/mod.rs b/lib/saluki-components/src/common/otlp/mod.rs index 61807e9ee14..2c1122164d7 100644 --- a/lib/saluki-components/src/common/otlp/mod.rs +++ b/lib/saluki-components/src/common/otlp/mod.rs @@ -86,7 +86,7 @@ pub struct Metrics { metrics_errors_dispatch: Counter, metrics_errors_flush: Counter, traces_errors_bad_request: Counter, - spans_dropped_foreign_trace: Counter, + spans_dropped_invalid_trace_id: Counter, spans_malformed_peer_service_truncate: Counter, spans_malformed_peer_service_invalid: Counter, spans_malformed_base_service_truncate: Counter, @@ -150,10 +150,9 @@ impl Metrics { &self.traces_errors_bad_request } - /// Spans dropped because their trace group mixed spans from different full trace IDs (two - /// traces sharing a low 64-bit half). - pub fn spans_dropped_foreign_trace(&self) -> &Counter { - &self.spans_dropped_foreign_trace + /// Spans dropped because their trace has an invalid trace ID: a length other than 0 or 16 bytes, or a zero low half. + pub fn spans_dropped_invalid_trace_id(&self) -> &Counter { + &self.spans_dropped_invalid_trace_id } pub fn spans_malformed_peer_service_truncate(&self) -> &Counter { @@ -193,7 +192,7 @@ impl Metrics { metrics_errors_dispatch: Counter::noop(), metrics_errors_flush: Counter::noop(), traces_errors_bad_request: Counter::noop(), - spans_dropped_foreign_trace: Counter::noop(), + spans_dropped_invalid_trace_id: Counter::noop(), spans_malformed_peer_service_truncate: Counter::noop(), spans_malformed_peer_service_invalid: Counter::noop(), spans_malformed_base_service_truncate: Counter::noop(), @@ -240,9 +239,9 @@ pub fn build_metrics(component_context: &ComponentContext) -> Metrics { metrics_errors_flush: builder.register_counter_with_tags("component_errors_total", [("reason", "flush")]), traces_errors_bad_request: builder .register_counter_with_tags("component_errors_total", [("reason", "bad_request")]), - spans_dropped_foreign_trace: builder.register_counter_with_tags( + spans_dropped_invalid_trace_id: builder.register_counter_with_tags( "component_events_dropped_total", - [("message_type", "otlp_spans"), ("reason", "foreign_span")], + [("message_type", "otlp_spans"), ("reason", "invalid_trace_id")], ), spans_malformed_peer_service_truncate: builder.register_counter_with_tags( "component_spans_malformed_total", diff --git a/lib/saluki-components/src/common/otlp/traces/translator.rs b/lib/saluki-components/src/common/otlp/traces/translator.rs index 2a9fd9a6706..2662ac33b78 100644 --- a/lib/saluki-components/src/common/otlp/traces/translator.rs +++ b/lib/saluki-components/src/common/otlp/traces/translator.rs @@ -1,4 +1,3 @@ -use std::collections::hash_map::IntoIter; use std::collections::HashMap; use std::num::NonZeroUsize; use std::sync::Arc; @@ -212,18 +211,117 @@ fn resolve_client_computed_stats(attributes: &[otlp_common::KeyValue]) -> bool { } struct TraceEntry { + /// Low 8 bytes of the trace ID. It identifies the trace. + trace_id_low: u64, + /// High 8 bytes of the trace ID: the first non-zero high half of the trace's spans, or zero if none has one. + trace_id_high: u64, spans: Vec, priority: Option, - trace_id_hex: Option, - /// High 8 bytes of the 128-bit trace ID (captured from the first span). - trace_id_high: u64, + /// The hex form of the trace ID, for the spans with a zero high half (first) and for the spans with a non-zero one + /// (second). A trace has at most one non-zero high half, so these two cover all of its spans. + trace_id_hex: [Option; 2], /// Set when any span in the trace has a span ID of zero. Mirrors `normalizeV1` /// (`pkg/trace/agent/normalizer.go`), which drops such a span along with the chunk containing it. dropped: bool, - /// Whether the group failed the full trace ID consistency check and must be dropped whole. + /// Whether the group has an invalid trace ID and must be dropped whole. rejected: bool, } +impl TraceEntry { + /// Returns the hex form of the trace ID of a span, which has the given high half. + /// + /// Spans of the same ID share one string. A span of the trace with another high half gets the hex form of its own + /// ID, so that each span names its own trace ID. + fn trace_id_hex(&mut self, trace_id: &[u8], trace_id_high: u64) -> Option { + let cached = &mut self.trace_id_hex[usize::from(trace_id_high != 0)]; + if let Some(hex) = cached { + return Some(hex.clone()); + } + + let hex = trace_id_hex_meta(trace_id)?; + *cached = Some(hex.clone()); + Some(hex) + } + + fn new(trace_id_high: u64, trace_id_low: u64) -> Self { + Self { + trace_id_low, + trace_id_high, + spans: Vec::new(), + priority: None, + trace_id_hex: [None, None], + dropped: false, + rejected: false, + } + } +} + +/// The traces of one `ResourceSpans`, in order of first appearance. +/// +/// The low 64 bits of a trace ID identify a trace. The high 64 bits are an optional extension: a hop that only +/// understands 64-bit IDs drops them, so spans of one trace can arrive with a high half and others without one (zero). +/// A zero high half therefore means "absent" and is compatible with any high half. Spans that share a low half are only +/// split into separate traces when they carry two different non-zero high halves, which is positive evidence of two +/// traces. A span with a zero high half joins the first such trace by order of first appearance, so the result does not +/// depend on hashing. +#[derive(Default)] +struct TraceGroups { + traces: Vec, + /// The first trace of each low half, by order of first appearance. A span with a zero high half joins it. Its high + /// half is zero until a span that carries one joins it. + first_trace_by_low_half: FastHashMap, + /// The traces that have a non-zero high half, by their full trace ID. A span with a non-zero high half finds its + /// trace here, so many traces that share a low half cost no more than one trace does. + traces_by_full_id: FastHashMap<(u64, u64), usize>, +} + +impl TraceGroups { + fn with_capacity(capacity: usize) -> Self { + let mut first_trace_by_low_half = FastHashMap::default(); + first_trace_by_low_half.reserve(capacity); + Self { + traces: Vec::with_capacity(capacity), + first_trace_by_low_half, + traces_by_full_id: FastHashMap::default(), + } + } + + /// Returns the trace that a span with the given halves of its trace ID belongs to, creating it if needed. + fn trace_for(&mut self, trace_id_high: u64, trace_id_low: u64) -> &mut TraceEntry { + let index = if trace_id_high == 0 { + // A zero high half is absent, so the span joins the first trace of its low half. + match self.first_trace_by_low_half.get(&trace_id_low) { + Some(&index) => index, + None => self.push_trace(0, trace_id_low), + } + } else if let Some(&index) = self.traces_by_full_id.get(&(trace_id_high, trace_id_low)) { + index + } else { + let index = match self.first_trace_by_low_half.get(&trace_id_low) { + // The first trace of this low half has no high half yet, so this span gives it one. + Some(&index) if self.traces[index].trace_id_high == 0 => { + self.traces[index].trace_id_high = trace_id_high; + index + } + // Any other trace of this low half has a different non-zero high half, so this span starts a new one. + _ => self.push_trace(trace_id_high, trace_id_low), + }; + self.traces_by_full_id.insert((trace_id_high, trace_id_low), index); + index + }; + + &mut self.traces[index] + } + + /// Adds a trace and returns its index. + fn push_trace(&mut self, trace_id_high: u64, trace_id_low: u64) -> usize { + let index = self.traces.len(); + self.traces.push(TraceEntry::new(trace_id_high, trace_id_low)); + self.first_trace_by_low_half.entry(trace_id_low).or_insert(index); + index + } +} + /// Settings of OTLP trace translation. #[derive(Clone, Debug, PartialEq)] pub struct OtlpTracesSettings { @@ -379,9 +477,8 @@ impl OtlpTracesTranslator { std::mem::take(&mut resource_meta.span_attributes), ); - let mut traces_by_id: FastHashMap = FastHashMap::default(); let trace_count_hint = resource_spans.scope_spans.len(); - traces_by_id.reserve(trace_count_hint); + let mut trace_groups = TraceGroups::with_capacity(trace_count_hint); // The sender's SDK identity, from before enrichment could replace those attributes with its own tags. let spans_received = metrics @@ -395,14 +492,7 @@ impl OtlpTracesTranslator { for span in scope_spans.spans { let trace_id = convert_trace_id(&span.trace_id); let trace_id_high = convert_trace_id_high(&span.trace_id); - let entry = traces_by_id.entry(trace_id).or_insert_with(|| TraceEntry { - spans: Vec::new(), - priority: None, - trace_id_hex: None, - trace_id_high, - dropped: false, - rejected: false, - }); + let entry = trace_groups.trace_for(trace_id_high, trace_id); // Once a trace is headed for the drop bin, skip the remaining spans entirely rather // than paying for their conversion only to discard the results at emit time. @@ -417,15 +507,7 @@ impl OtlpTracesTranslator { entry.rejected = true; } - // Full trace ID consistency: spans in a group must carry the same full trace ID - // as the group's first span. - if entry.trace_id_high != trace_id_high { - entry.rejected = true; - } - - if entry.trace_id_hex.is_none() { - entry.trace_id_hex = trace_id_hex_meta(&span.trace_id); - } + let trace_id_hex = entry.trace_id_hex(&span.trace_id, trace_id_high); let dd_span = if receive_v1 { otel_span_to_dd_span_v1( @@ -435,7 +517,7 @@ impl OtlpTracesTranslator { conversion, interner, string_builder, - entry.trace_id_hex.as_ref(), + trace_id_hex.as_ref(), ) } else { otel_span_to_dd_span( @@ -446,7 +528,7 @@ impl OtlpTracesTranslator { registry, interner, string_builder, - entry.trace_id_hex.as_ref(), + trace_id_hex.as_ref(), ) }; @@ -507,7 +589,7 @@ impl OtlpTracesTranslator { ..ReceiverMetadata::new() }), resource_meta, - entries: traces_by_id.into_iter(), + entries: trace_groups.traces.into_iter(), metrics: metrics.clone(), } } @@ -517,7 +599,7 @@ struct OtlpTraceEventsIter { ingest_info: TraceIngestInfo, receiver: Arc, resource_meta: OtlpResourceMeta, - entries: IntoIter, + entries: std::vec::IntoIter, metrics: Metrics, } @@ -525,15 +607,15 @@ impl Iterator for OtlpTraceEventsIter { type Item = Event; fn next(&mut self) -> Option { - for (trace_id_low, entry) in self.entries.by_ref() { + for entry in self.entries.by_ref() { if entry.dropped { continue; } if entry.rejected { - // Two different traces glued together by a shared low half: drop the group whole. + // An invalid trace ID: drop the group whole. self.metrics - .spans_dropped_foreign_trace() + .spans_dropped_invalid_trace_id() .increment(entry.spans.len() as u64); continue; } @@ -548,7 +630,7 @@ impl Iterator for OtlpTraceEventsIter { // this is the first point where a complete (spans + resource metadata + priority) // picture is available for a single trace. Resource metadata is shared across all // traces in a ResourceSpans batch, so it lives on the iterator rather than per-entry. - trace.trace_id_low = trace_id_low; + trace.trace_id_low = entry.trace_id_low; trace.trace_id_high = entry.trace_id_high; trace.priority = entry.priority; trace.payload.env = self.resource_meta.env.clone(); @@ -1928,8 +2010,8 @@ mod tests { } #[test] - fn convert_trace_id_uses_agent_grouping_key() { - // Pins the grouping key we derive from the upstream OTLP ingest: the low 8 bytes of the + fn convert_trace_id_splits_the_grouping_key_into_halves() { + // Pins the two halves of the grouping key: the low 8 bytes and the high 8 bytes of the // 16-byte big-endian trace ID. let id: [u8; 16] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]; assert_eq!( @@ -1947,52 +2029,249 @@ mod tests { assert_eq!(convert_trace_id_high(&[0xAA; 8]), 0); } + const LOW_HALF: u64 = 0xAAAA_AAAA_AAAA_AAAA; + + /// Returns the span IDs of a trace, as the first byte of each, in span order. + fn span_id_bytes(trace: &Trace) -> Vec { + trace + .spans() + .iter() + .map(|span| span.span_id().to_be_bytes()[0]) + .collect() + } + + #[test] + fn translate_spans_keeps_a_zero_and_a_nonzero_high_half_of_one_low_half_in_one_trace() { + // A zero high half is absent, so it is compatible with a non-zero one in either span order. The trace carries + // the non-zero high half. + for (first, second) in [(0, 5), (5, 0)] { + let rs = build_resource_spans( + vec![], + vec![ + span(trace_id16(first, LOW_HALF), [1u8; 8], vec![]), + span(trace_id16(second, LOW_HALF), [2u8; 8], vec![]), + ], + ); + + let traces = translate(rs); + assert_eq!(traces.len(), 1, "high halves {first} and {second} are one trace"); + assert_eq!(span_id_bytes(&traces[0]), vec![1, 2]); + assert_eq!(traces[0].trace_id_low, LOW_HALF); + assert_eq!(traces[0].trace_id_high, 5); + } + } + #[test] - fn translate_spans_rejects_groups_with_mixed_full_trace_ids() { - let low = u64::from_be_bytes([0xAA; 8]); + fn translate_spans_splits_two_different_nonzero_high_halves_of_one_low_half() { let rs = build_resource_spans( vec![], vec![ - span(trace_id16(0x0101_0101_0101_0101, low), [1u8; 8], vec![]), - span(trace_id16(0x0202_0202_0202_0202, low), [2u8; 8], vec![]), + span(trace_id16(1, LOW_HALF), [1u8; 8], vec![]), + span(trace_id16(2, LOW_HALF), [2u8; 8], vec![]), span(trace_id16(0, 0x0BBB_BBBB_BBBB_BBBB), [3u8; 8], vec![]), ], ); let traces = translate(rs); + assert_eq!(traces.len(), 3, "each trace is kept, in order of first appearance"); + + assert_eq!((traces[0].trace_id_high, traces[0].trace_id_low), (1, LOW_HALF)); + assert_eq!(span_id_bytes(&traces[0]), vec![1]); + assert_eq!((traces[1].trace_id_high, traces[1].trace_id_low), (2, LOW_HALF)); + assert_eq!(span_id_bytes(&traces[1]), vec![2]); assert_eq!( - traces.len(), - 1, - "the mixed group is dropped; the unrelated trace survives" + (traces[2].trace_id_high, traces[2].trace_id_low), + (0, 0x0BBB_BBBB_BBBB_BBBB) ); - assert_eq!(traces[0].trace_id_low, 0x0BBB_BBBB_BBBB_BBBB); + assert_eq!(span_id_bytes(&traces[2]), vec![3]); } + // A request can carry many spans whose trace IDs share a low half and differ in a non-zero high half. Each span must + // find its trace directly, not by scanning the traces before it, or one request could make grouping quadratic. #[test] - fn translate_spans_rejects_mixed_zero_and_nonzero_high_halves() { - // A zero high half and a nonzero high half are different full trace IDs, in either span - // order. Both IDs are canonical 16-byte OTLP IDs here; the OTLP spans always carry the - // full 128-bit ID, so unlike legacy tracer chunks the high halves are always compared. - let id_zero_high = trace_id16(0, u64::from_be_bytes([0xAA; 8])).to_vec(); - let id_full = trace_id16(0x0101_0101_0101_0101, u64::from_be_bytes([0xAA; 8])).to_vec(); - - let zero_high_first = build_resource_spans( + fn trace_groups_find_each_of_many_high_halves_of_one_low_half_directly() { + let count = 20_000u64; + let mut groups = TraceGroups::with_capacity(0); + + for high in 1..=count { + assert_eq!(groups.trace_for(high, LOW_HALF).trace_id_high, high); + } + for high in (1..=count).rev() { + assert_eq!(groups.trace_for(high, LOW_HALF).trace_id_high, high); + } + + assert_eq!(groups.traces.len(), count as usize); + } + + #[test] + fn trace_groups_apply_the_zero_high_half_rule() { + let mut groups = TraceGroups::with_capacity(0); + + // A zero high half creates a trace, and a later non-zero one joins it and gives it its high half. + assert_eq!(groups.trace_for(0, LOW_HALF).trace_id_high, 0); + assert_eq!(groups.trace_for(5, LOW_HALF).trace_id_high, 5); + assert_eq!(groups.traces.len(), 1); + + // A different non-zero high half is another trace, and each is found again by its own high half. + assert_eq!(groups.trace_for(6, LOW_HALF).trace_id_high, 6); + assert_eq!(groups.traces.len(), 2); + assert_eq!(groups.trace_for(5, LOW_HALF).trace_id_high, 5); + assert_eq!(groups.trace_for(6, LOW_HALF).trace_id_high, 6); + assert_eq!(groups.traces.len(), 2); + + // A zero high half joins the first trace of its low half by order of appearance. + assert_eq!(groups.trace_for(0, LOW_HALF).trace_id_high, 5); + assert_eq!(groups.traces.len(), 2); + + // Another low half is independent. + assert_eq!(groups.trace_for(0, LOW_HALF + 1).trace_id_high, 0); + assert_eq!(groups.traces.len(), 3); + } + + // The hex form of a trace ID is shared by the spans that have the same ID, also in a trace whose spans do not all + // carry the same high half. + #[test] + fn trace_entries_share_one_hex_string_for_each_high_half_of_a_mixed_trace() { + let mut entry = TraceEntry::new(0, LOW_HALF); + let without_high = trace_id16(0, LOW_HALF); + let with_high = trace_id16(5, LOW_HALF); + + let first_without_high = entry.trace_id_hex(&without_high, 0).unwrap(); + let first_with_high = entry.trace_id_hex(&with_high, 5).unwrap(); + let second_with_high = entry.trace_id_hex(&with_high, 5).unwrap(); + let second_without_high = entry.trace_id_hex(&without_high, 0).unwrap(); + + assert_ne!(first_without_high, first_with_high, "each span names its own trace ID"); + assert_eq!(first_with_high.as_ptr(), second_with_high.as_ptr()); + assert_eq!(first_without_high.as_ptr(), second_without_high.as_ptr()); + } + + #[test] + fn translate_spans_puts_a_zero_high_half_in_the_first_nonzero_trace_by_appearance() { + // The span with a zero high half joins the trace of the first non-zero high half to appear, wherever it sits + // among the spans. The spans have the span IDs 1, 2 and 3 in the order they are sent. + for (high_halves, expected) in [ + // Zero first: high half 1 appears first among the non-zero ones. + ([0, 1, 2], [(1, vec![1, 2]), (2, vec![3])]), + ([1, 0, 2], [(1, vec![1, 2]), (2, vec![3])]), + ([1, 2, 0], [(1, vec![1, 3]), (2, vec![2])]), + ([2, 1, 0], [(2, vec![1, 3]), (1, vec![2])]), + ] { + let spans = high_halves + .into_iter() + .zip(1u8..) + .map(|(high, span_id)| span(trace_id16(high, LOW_HALF), [span_id; 8], vec![])) + .collect(); + + let traces = translate(build_resource_spans(vec![], spans)); + let actual: Vec<(u64, Vec)> = traces + .iter() + .map(|trace| (trace.trace_id_high, span_id_bytes(trace))) + .collect(); + assert_eq!(actual, expected, "high halves {high_halves:?}"); + } + } + + #[test] + fn translate_spans_tags_each_span_with_its_own_trace_id() { + // Spans of one trace that carry different high halves keep the hex form of their own ID. + let rs = build_resource_spans( + vec![], + vec![ + span(trace_id16(0, LOW_HALF), [1u8; 8], vec![]), + span(trace_id16(5, LOW_HALF), [2u8; 8], vec![]), + span(trace_id16(5, LOW_HALF), [3u8; 8], vec![]), + ], + ); + + let traces = translate(rs); + assert_eq!(traces.len(), 1); + let hex = |index: usize| { + traces[0].spans()[index] + .attributes + .get("otel.trace_id") + .and_then(AttributeValue::as_string) + .map(|value| value.to_string()) + }; + assert_eq!(hex(0).as_deref(), Some("0000000000000000aaaaaaaaaaaaaaaa")); + assert_eq!(hex(1).as_deref(), Some("0000000000000005aaaaaaaaaaaaaaaa")); + assert_eq!(hex(2).as_deref(), Some("0000000000000005aaaaaaaaaaaaaaaa")); + } + + #[test] + fn translate_spans_groups_spans_with_the_same_full_trace_id() { + let id = trace_id16(0x0101_0101_0101_0101, LOW_HALF); + let rs = build_resource_spans(vec![], vec![span(id, [1u8; 8], vec![]), span(id, [2u8; 8], vec![])]); + + let traces = translate(rs); + assert_eq!(traces.len(), 1); + assert_eq!(traces[0].spans().len(), 2); + assert_eq!(traces[0].trace_id_high, 0x0101_0101_0101_0101); + assert_eq!(traces[0].trace_id_low, LOW_HALF); + } + + #[test] + fn translate_spans_merges_equal_nonzero_high_halves_across_scope_spans() { + // Grouping covers every scope of one ResourceSpans: equal non-zero high halves and a zero one share a trace, + // and a different non-zero high half does not. + let scope = |spans| ScopeSpans { + spans, + ..Default::default() + }; + let rs = ResourceSpans { + scope_spans: vec![ + scope(vec![ + span(trace_id16(1, LOW_HALF), [1u8; 8], vec![]), + span(trace_id16(2, LOW_HALF), [2u8; 8], vec![]), + ]), + scope(vec![ + span(trace_id16(1, LOW_HALF), [3u8; 8], vec![]), + span(trace_id16(0, LOW_HALF), [4u8; 8], vec![]), + ]), + ], + ..Default::default() + }; + + let traces = translate(rs); + assert_eq!(traces.len(), 2); + assert_eq!(traces[0].trace_id_high, 1); + assert_eq!(span_id_bytes(&traces[0]), vec![1, 3, 4]); + assert_eq!(traces[1].trace_id_high, 2); + assert_eq!(span_id_bytes(&traces[1]), vec![2]); + } + + #[test] + fn translate_spans_drops_only_the_zero_span_id_trace_among_same_low_half_traces() { + // The span ID zero rule applies to the trace the span belongs to, not to every trace with the same low half. + let rs = build_resource_spans( vec![], vec![ - span_raw(id_zero_high.clone(), [1u8; 8], vec![]), - span_raw(id_full.clone(), [2u8; 8], vec![]), + span(trace_id16(1, LOW_HALF), [0u8; 8], vec![]), + span(trace_id16(2, LOW_HALF), [2u8; 8], vec![]), ], ); - assert_eq!(translate(zero_high_first).len(), 0); - let full_first = build_resource_spans( + let traces = translate(rs); + assert_eq!(traces.len(), 1); + assert_eq!(traces[0].trace_id_high, 2); + } + + #[test] + fn translate_spans_drops_a_zero_high_span_with_a_zero_span_id_with_its_trace() { + // A span with a zero high half and a zero span ID belongs to the trace it is compatible with, so that whole + // trace is dropped, while a trace with another non-zero high half survives. + let rs = build_resource_spans( vec![], vec![ - span_raw(id_full, [1u8; 8], vec![]), - span_raw(id_zero_high, [2u8; 8], vec![]), + span(trace_id16(1, LOW_HALF), [1u8; 8], vec![]), + span(trace_id16(2, LOW_HALF), [2u8; 8], vec![]), + span(trace_id16(0, LOW_HALF), [0u8; 8], vec![]), ], ); - assert_eq!(translate(full_first).len(), 0); + + let traces = translate(rs); + assert_eq!(traces.len(), 1); + assert_eq!(traces[0].trace_id_high, 2); } #[test] diff --git a/test/correctness/cases/otlp-traces-conversion/config.yaml b/test/correctness/cases/otlp-traces-conversion/config.yaml index a424ac6a203..a27d6a4b033 100644 --- a/test/correctness/cases/otlp-traces-conversion/config.yaml +++ b/test/correctness/cases/otlp-traces-conversion/config.yaml @@ -46,10 +46,10 @@ procedure: baseline: intake-agent otlp_direct_analysis_mode: true traces: - # The fixture holds 92 spans. The Agent drops four of them, and ADP drops four more. At least 84 spans in 78 - # traces reach each side. - min_traces: 78 - min_spans: 84 + # The fixture holds 92 spans. Both sides drop four of them, so 88 spans in 81 traces reach each side. A trace + # is a distinct low half of the trace ID, so the spans of `probe-conv-high` that share a low half count once. + min_traces: 81 + min_spans: 88 # The spans that both sides send with the same service, name and resource. A span whose service, name or # resource differs between the sides is in `known_differences`. spans: @@ -127,8 +127,12 @@ procedure: - {service: probe-conv-dd-env, name: Internal, resource: otlpprobe.conv.resource.datadog_env_version} - {service: probe-conv-dd-host, name: Internal, resource: otlpprobe.conv.resource.datadog_host_name} - {service: probe-conv-fargate, name: Internal, resource: otlpprobe.conv.resource.fargate} + - {service: probe-conv-high, name: Internal, resource: otlpprobe.conv.high.mixed_a} + - {service: probe-conv-high, name: Internal, resource: otlpprobe.conv.high.mixed_b} - {service: probe-conv-high, name: Internal, resource: otlpprobe.conv.high.same_a} - {service: probe-conv-high, name: Internal, resource: otlpprobe.conv.high.same_b} + - {service: probe-conv-high, name: Internal, resource: otlpprobe.conv.high.zero_half_a} + - {service: probe-conv-high, name: Internal, resource: otlpprobe.conv.high.zero_half_b} - {service: probe-conv-host, name: Internal, resource: otlpprobe.conv.resource.host_name} - {service: probe-conv-meta, name: Internal, resource: otlpprobe.conv.resource.from_resource} - {service: probe-conv-meta-span, name: Internal, resource: otlpprobe.conv.resource.from_span} @@ -228,13 +232,13 @@ procedure: kinds: [value] when: {service: [probe-conv-fargate], resource: [otlpprobe.conv.resource.fargate]} reason: ADP writes the `task_arn` container tag of a Fargate task twice. The Agent writes it once. - # The spans of a trace whose spans have different high halves of the trace ID. - - gap: gap/otlp-high-trace-id-group + # Spans that ADP splits into traces of their own. + - gap: gap/otlp-split-high-trace-ids issue: 3445 - paths: [spans] - kinds: [missing] - when: {service: [probe-conv-high], resource: [otlpprobe.conv.high.mixed_a, otlpprobe.conv.high.mixed_b, otlpprobe.conv.high.zero_half_a, otlpprobe.conv.high.zero_half_b]} - reason: The Agent groups spans by the low half of the trace ID and keeps them. ADP drops the group. + paths: [span.meta._dd.p.dm] + kinds: [extra] + when: {service: [probe-conv-high], resource: [otlpprobe.conv.high.mixed_b]} + reason: ADP puts spans whose trace IDs share a low half but have two different non-zero high halves in separate traces. This is intentional. The second trace has a root span of its own, which carries the decision maker. The Agent keeps both spans in one chunk with a single root. - step: intake_from on: intake-adp telemetry: spans