Skip to content

Commit 128e83b

Browse files
committed
fix(traces): address PR review feedback
- Deduplicate extract_propagation_tags into shared helper in traces::propagation - Use case-insensitive matching for ot-baggage-* header prefix - Update datadog-opentelemetry to f51cefc
1 parent 97bb150 commit 128e83b

3 files changed

Lines changed: 45 additions & 23 deletions

File tree

bottlecap/src/lifecycle/invocation/processor.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,17 +1352,7 @@ impl Processor {
13521352

13531353
fn extract_propagation_tags(carrier: &HashMap<String, String>) -> HashMap<String, String> {
13541354
let carrier_tags = carrier.get(DATADOG_TAGS_KEY).map_or("", String::as_str);
1355-
carrier_tags
1356-
.split(',')
1357-
.filter_map(|pair| {
1358-
let (k, v) = pair.split_once('=')?;
1359-
if k.starts_with("_dd.p.") {
1360-
Some((k.to_string(), v.to_string()))
1361-
} else {
1362-
None
1363-
}
1364-
})
1365-
.collect()
1355+
crate::traces::propagation::extract_propagation_tags(carrier_tags)
13661356
}
13671357

13681358
#[cfg(test)]

bottlecap/src/lifecycle/invocation/triggers/step_function_event.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -240,17 +240,7 @@ impl StepFunctionEvent {
240240
}
241241

242242
fn extract_propagation_tags(tags_str: &str) -> HashMap<String, String> {
243-
tags_str
244-
.split(',')
245-
.filter_map(|pair| {
246-
let (k, v) = pair.split_once('=')?;
247-
if k.starts_with("_dd.p.") {
248-
Some((k.to_string(), v.to_string()))
249-
} else {
250-
None
251-
}
252-
})
253-
.collect()
243+
crate::traces::propagation::extract_propagation_tags(tags_str)
254244
}
255245

256246
impl ServiceNameResolver for StepFunctionEvent {

bottlecap/src/traces/propagation/mod.rs

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::collections::HashMap;
12
use std::sync::Arc;
23

34
use crate::config;
@@ -8,6 +9,22 @@ use datadog_opentelemetry::propagation::{
89
pub mod carrier;
910

1011
const BAGGAGE_PREFIX: &str = "ot-baggage-";
12+
const PROPAGATION_TAG_PREFIX: &str = "_dd.p.";
13+
14+
#[must_use]
15+
pub fn extract_propagation_tags(tags_str: &str) -> HashMap<String, String> {
16+
tags_str
17+
.split(',')
18+
.filter_map(|pair| {
19+
let (k, v) = pair.split_once('=')?;
20+
if k.starts_with(PROPAGATION_TAG_PREFIX) {
21+
Some((k.to_string(), v.to_string()))
22+
} else {
23+
None
24+
}
25+
})
26+
.collect()
27+
}
1128

1229
// Thin wrapper around dd-trace-rs's propagator to add `ot-baggage-*` header
1330
// extraction, which is not yet supported upstream in datadog-opentelemetry.
@@ -37,7 +54,8 @@ impl DatadogCompositePropagator {
3754
let keys = carrier.keys();
3855

3956
for key in keys {
40-
if let Some(stripped) = key.strip_prefix(BAGGAGE_PREFIX) {
57+
let lower = key.to_ascii_lowercase();
58+
if let Some(stripped) = lower.strip_prefix(BAGGAGE_PREFIX) {
4159
context.tags.insert(
4260
stripped.to_string(),
4361
carrier.get(key).unwrap_or_default().to_string(),
@@ -198,4 +216,28 @@ pub mod tests {
198216
assert_eq!(context.tags.len(), 1);
199217
assert_eq!(context.tags.get("key1").expect("Missing tag"), "value1");
200218
}
219+
220+
#[test]
221+
fn test_attach_baggage_multiple_keys() {
222+
let mut context = SpanContext::default();
223+
let carrier = HashMap::from([
224+
("ot-baggage-key1".to_string(), "value1".to_string()),
225+
("ot-baggage-key2".to_string(), "value2".to_string()),
226+
("x-datadog-trace-id".to_string(), "123".to_string()),
227+
]);
228+
229+
DatadogCompositePropagator::attach_baggage(&mut context, &carrier);
230+
231+
assert_eq!(context.tags.len(), 2);
232+
assert_eq!(context.tags.get("key1").expect("Missing tag"), "value1");
233+
assert_eq!(context.tags.get("key2").expect("Missing tag"), "value2");
234+
}
235+
236+
#[test]
237+
fn test_extract_propagation_tags() {
238+
let tags = extract_propagation_tags("_dd.p.tid=abc123,any=tag,_dd.p.dm=-4");
239+
assert_eq!(tags.len(), 2);
240+
assert_eq!(tags.get("_dd.p.tid").expect("Missing tag"), "abc123");
241+
assert_eq!(tags.get("_dd.p.dm").expect("Missing tag"), "-4");
242+
}
201243
}

0 commit comments

Comments
 (0)