From 6db72607f9a1cd522bb0608b572dbf1debe2cd75 Mon Sep 17 00:00:00 2001 From: vianney Date: Mon, 18 May 2026 20:30:09 +0200 Subject: [PATCH 1/6] feat(trace-utils): add from_string to span text --- .../src/trace_exporter/trace_serializer.rs | 16 ++-- .../src/span_concentrator/aggregation.rs | 83 ++++++++++--------- .../src/span_concentrator/tests.rs | 47 ++++++----- libdd-trace-stats/src/stats_exporter.rs | 2 +- libdd-trace-utils/src/span/mod.rs | 16 ++-- libdd-trace-utils/src/span/v04/mod.rs | 43 ++++++---- 6 files changed, 111 insertions(+), 96 deletions(-) diff --git a/libdd-data-pipeline/src/trace_exporter/trace_serializer.rs b/libdd-data-pipeline/src/trace_exporter/trace_serializer.rs index 2a257c7e82..c710a33a11 100644 --- a/libdd-data-pipeline/src/trace_exporter/trace_serializer.rs +++ b/libdd-data-pipeline/src/trace_exporter/trace_serializer.rs @@ -271,10 +271,10 @@ mod tests { let original_span = &original_traces[0][0]; let deserialized_span = &deserialized_traces[0][0]; - assert_eq!(original_span.name, deserialized_span.name); - assert_eq!(original_span.service, deserialized_span.service); - assert_eq!(original_span.resource, deserialized_span.resource); - assert_eq!(original_span.r#type, deserialized_span.r#type); + assert_eq!(original_span.name, deserialized_span.name.as_ref()); + assert_eq!(original_span.service, deserialized_span.service.as_ref()); + assert_eq!(original_span.resource, deserialized_span.resource.as_ref()); + assert_eq!(original_span.r#type, deserialized_span.r#type.as_ref()); assert_eq!(original_span.start, deserialized_span.start); assert_eq!(original_span.duration, deserialized_span.duration); assert_eq!(original_span.span_id, deserialized_span.span_id); @@ -306,10 +306,10 @@ mod tests { let original_span = &original_traces[0][0]; let deserialized_span = &deserialized_traces[0][0]; - assert_eq!(original_span.name, deserialized_span.name); - assert_eq!(original_span.service, deserialized_span.service); - assert_eq!(original_span.resource, deserialized_span.resource); - assert_eq!(original_span.r#type, deserialized_span.r#type); + assert_eq!(original_span.name, deserialized_span.name.as_ref()); + assert_eq!(original_span.service, deserialized_span.service.as_ref()); + assert_eq!(original_span.resource, deserialized_span.resource.as_ref()); + assert_eq!(original_span.r#type, deserialized_span.r#type.as_ref()); assert_eq!(original_span.start, deserialized_span.start); assert_eq!(original_span.duration, deserialized_span.duration); assert_eq!(original_span.span_id, deserialized_span.span_id); diff --git a/libdd-trace-stats/src/span_concentrator/aggregation.rs b/libdd-trace-stats/src/span_concentrator/aggregation.rs index d277e47db6..58ba2b73d4 100644 --- a/libdd-trace-stats/src/span_concentrator/aggregation.rs +++ b/libdd-trace-stats/src/span_concentrator/aggregation.rs @@ -8,7 +8,6 @@ use hashbrown::HashMap; use libdd_trace_obfuscation::ip_address::quantize_peer_ip_addresses; use libdd_trace_protobuf::pb; -use libdd_trace_utils::span::SpanText; use std::borrow::{Borrow, Cow}; use crate::span_concentrator::StatSpan; @@ -292,12 +291,9 @@ impl From for OwnedAggregationKey { } /// Return true if we care about peer tags on the span -fn should_track_peer_tags(span_kind: T) -> bool -where - T: SpanText, -{ +fn should_track_peer_tags(span_kind: &str) -> bool { matches!( - span_kind.borrow().to_lowercase().as_str(), + span_kind.to_lowercase().as_str(), "client" | "producer" | "consumer" ) } @@ -865,12 +861,15 @@ mod tests { // Span with peer tags with peertags aggregation enabled ( SpanSlice { - service: "service", - name: "op", - resource: "res", + service: "service".into(), + name: "op".into(), + resource: "res".into(), span_id: 1, parent_id: 0, - meta: HashMap::from([("span.kind", "client"), ("aws.s3.bucket", "bucket-a")]), + meta: HashMap::from([ + ("span.kind".into(), "client".into()), + ("aws.s3.bucket".into(), "bucket-a".into()), + ]), ..Default::default() }, FixedAggregationKey { @@ -886,16 +885,16 @@ mod tests { // Span with multiple peer tags with peertags aggregation enabled ( SpanSlice { - service: "service", - name: "op", - resource: "res", + service: "service".into(), + name: "op".into(), + resource: "res".into(), span_id: 1, parent_id: 0, meta: HashMap::from([ - ("span.kind", "producer"), - ("aws.s3.bucket", "bucket-a"), - ("db.instance", "dynamo.test.us1"), - ("db.system", "dynamodb"), + ("span.kind".into(), "producer".into()), + ("aws.s3.bucket".into(), "bucket-a".into()), + ("db.instance".into(), "dynamo.test.us1".into()), + ("db.system".into(), "dynamodb".into()), ]), ..Default::default() }, @@ -917,16 +916,16 @@ mod tests { // server ( SpanSlice { - service: "service", - name: "op", - resource: "res", + service: "service".into(), + name: "op".into(), + resource: "res".into(), span_id: 1, parent_id: 0, meta: HashMap::from([ - ("span.kind", "server"), - ("aws.s3.bucket", "bucket-a"), - ("db.instance", "dynamo.test.us1"), - ("db.system", "dynamodb"), + ("span.kind".into(), "server".into()), + ("aws.s3.bucket".into(), "bucket-a".into()), + ("db.instance".into(), "dynamo.test.us1".into()), + ("db.system".into(), "dynamodb".into()), ]), ..Default::default() }, @@ -971,15 +970,15 @@ mod tests { // IPv4 address peer tag gets replaced with blocked-ip-address let span_ipv4 = SpanSlice { - service: "service", - name: "op", - resource: "res", + service: "service".into(), + name: "op".into(), + resource: "res".into(), span_id: 1, parent_id: 0, meta: HashMap::from([ - ("span.kind", "client"), - ("peer.hostname", "10.1.2.3"), - ("db.instance", "my-db"), + ("span.kind".into(), "client".into()), + ("peer.hostname".into(), "10.1.2.3".into()), + ("db.instance".into(), "my-db".into()), ]), ..Default::default() }; @@ -998,14 +997,17 @@ mod tests { // IPv6 address peer tag gets replaced with blocked-ip-address let span_ipv6 = SpanSlice { - service: "service", - name: "op", - resource: "res", + service: "service".into(), + name: "op".into(), + resource: "res".into(), span_id: 1, parent_id: 0, meta: HashMap::from([ - ("span.kind", "client"), - ("peer.hostname", "2001:db8:3333:4444:CCCC:DDDD:EEEE:FFFF"), + ("span.kind".into(), "client".into()), + ( + "peer.hostname".into(), + "2001:db8:3333:4444:CCCC:DDDD:EEEE:FFFF".into(), + ), ]), ..Default::default() }; @@ -1022,12 +1024,15 @@ mod tests { // Non-IP peer tags pass through unchanged let span_non_ip = SpanSlice { - service: "service", - name: "op", - resource: "res", + service: "service".into(), + name: "op".into(), + resource: "res".into(), span_id: 1, parent_id: 0, - meta: HashMap::from([("span.kind", "client"), ("db.instance", "dynamo.test.us1")]), + meta: HashMap::from([ + ("span.kind".into(), "client".into()), + ("db.instance".into(), "dynamo.test.us1".into()), + ]), ..Default::default() }; let non_ip_keys = vec!["db.instance".to_string()]; diff --git a/libdd-trace-stats/src/span_concentrator/tests.rs b/libdd-trace-stats/src/span_concentrator/tests.rs index 25bbae29c0..6c3a433cd5 100644 --- a/libdd-trace-stats/src/span_concentrator/tests.rs +++ b/libdd-trace-stats/src/span_concentrator/tests.rs @@ -6,6 +6,7 @@ use crate::span_concentrator::aggregation::OwnedAggregationKey; use super::*; use libdd_trace_utils::span::{trace_utils::compute_top_level_span, v04::SpanSlice}; use rand::{thread_rng, Rng}; +use std::borrow::Cow; const BUCKET_SIZE: u64 = Duration::from_secs(2).as_nanos() as u64; @@ -44,11 +45,11 @@ fn get_test_span<'a>( parent_id, duration, start: get_timestamp_in_bucket(aligned_now, BUCKET_SIZE, offset) as i64 - duration, - service, - name: "query", - resource, + service: service.into(), + name: "query".into(), + resource: resource.into(), error, - r#type: "db", + r#type: "db".into(), ..Default::default() } } @@ -70,11 +71,11 @@ fn get_test_span_with_meta<'a>( now, span_id, parent_id, duration, offset, service, resource, error, ); for (k, v) in meta { - span.meta.insert(*k, *v); + span.meta.insert(Cow::Borrowed(*k), Cow::Borrowed(*v)); } span.metrics = HashMap::new(); for (k, v) in metrics { - span.metrics.insert(*k, *v); + span.metrics.insert(Cow::Borrowed(*k), *v); } span } @@ -649,7 +650,7 @@ fn test_ignore_partial_spans() { .get_mut(0) .unwrap() .metrics - .insert("_dd.partial_version", 830604.0); + .insert("_dd.partial_version".into(), 830604.0); compute_top_level_span(spans.as_mut_slice()); let mut concentrator = SpanConcentrator::new( Duration::from_nanos(BUCKET_SIZE), @@ -1159,112 +1160,112 @@ fn test_compute_stats_for_span_kind() { let test_cases: Vec<(SpanSlice, bool)> = vec![ ( SpanSlice { - meta: HashMap::from([("span.kind", "server")]), + meta: HashMap::from([("span.kind".into(), "server".into())]), ..Default::default() }, true, ), ( SpanSlice { - meta: HashMap::from([("span.kind", "consumer")]), + meta: HashMap::from([("span.kind".into(), "consumer".into())]), ..Default::default() }, true, ), ( SpanSlice { - meta: HashMap::from([("span.kind", "client")]), + meta: HashMap::from([("span.kind".into(), "client".into())]), ..Default::default() }, true, ), ( SpanSlice { - meta: HashMap::from([("span.kind", "producer")]), + meta: HashMap::from([("span.kind".into(), "producer".into())]), ..Default::default() }, true, ), ( SpanSlice { - meta: HashMap::from([("span.kind", "internal")]), + meta: HashMap::from([("span.kind".into(), "internal".into())]), ..Default::default() }, false, ), ( SpanSlice { - meta: HashMap::from([("span.kind", "SERVER")]), + meta: HashMap::from([("span.kind".into(), "SERVER".into())]), ..Default::default() }, true, ), ( SpanSlice { - meta: HashMap::from([("span.kind", "CONSUMER")]), + meta: HashMap::from([("span.kind".into(), "CONSUMER".into())]), ..Default::default() }, true, ), ( SpanSlice { - meta: HashMap::from([("span.kind", "CLIENT")]), + meta: HashMap::from([("span.kind".into(), "CLIENT".into())]), ..Default::default() }, true, ), ( SpanSlice { - meta: HashMap::from([("span.kind", "PRODUCER")]), + meta: HashMap::from([("span.kind".into(), "PRODUCER".into())]), ..Default::default() }, true, ), ( SpanSlice { - meta: HashMap::from([("span.kind", "INTERNAL")]), + meta: HashMap::from([("span.kind".into(), "INTERNAL".into())]), ..Default::default() }, false, ), ( SpanSlice { - meta: HashMap::from([("span.kind", "SerVER")]), + meta: HashMap::from([("span.kind".into(), "SerVER".into())]), ..Default::default() }, true, ), ( SpanSlice { - meta: HashMap::from([("span.kind", "ConSUMeR")]), + meta: HashMap::from([("span.kind".into(), "ConSUMeR".into())]), ..Default::default() }, true, ), ( SpanSlice { - meta: HashMap::from([("span.kind", "CLiENT")]), + meta: HashMap::from([("span.kind".into(), "CLiENT".into())]), ..Default::default() }, true, ), ( SpanSlice { - meta: HashMap::from([("span.kind", "PROducER")]), + meta: HashMap::from([("span.kind".into(), "PROducER".into())]), ..Default::default() }, true, ), ( SpanSlice { - meta: HashMap::from([("span.kind", "INtERNAL")]), + meta: HashMap::from([("span.kind".into(), "INtERNAL".into())]), ..Default::default() }, false, ), ( SpanSlice { - meta: HashMap::from([("span.kind", "")]), + meta: HashMap::from([("span.kind".into(), "".into())]), ..Default::default() }, false, diff --git a/libdd-trace-stats/src/stats_exporter.rs b/libdd-trace-stats/src/stats_exporter.rs index e0130804cd..da3cc5fa94 100644 --- a/libdd-trace-stats/src/stats_exporter.rs +++ b/libdd-trace-stats/src/stats_exporter.rs @@ -268,7 +268,7 @@ mod tests { for i in 1..100 { trace.push(SpanSlice { - service: "libdatadog-test", + service: "libdatadog-test".into(), duration: i, ..Default::default() }) diff --git a/libdd-trace-utils/src/span/mod.rs b/libdd-trace-utils/src/span/mod.rs index c52a7aa01f..e6358dfc7a 100644 --- a/libdd-trace-utils/src/span/mod.rs +++ b/libdd-trace-utils/src/span/mod.rs @@ -10,7 +10,7 @@ use crate::msgpack_decoder::decode::error::DecodeError; use crate::span::v05::dict::SharedDict; use libdd_tinybytes::{Bytes, BytesString}; use serde::Serialize; -use std::borrow::Borrow; +use std::borrow::{Borrow, Cow}; use std::fmt::Debug; use std::hash::Hash; use std::marker::PhantomData; @@ -20,13 +20,13 @@ use std::{fmt, ptr}; /// Trait representing the requirements for a type to be used as a Span "string" type. /// Note: Borrow is not required by the derived traits, but allows to access HashMap elements /// from a static str and check if the string is empty. -pub trait SpanText: Debug + Eq + Hash + Borrow + Serialize + Default { +pub trait SpanText: Debug + Eq + Hash + Borrow + Serialize + Default + From { fn from_static_str(value: &'static str) -> Self; } -impl SpanText for &str { +impl SpanText for Cow<'_, str> { fn from_static_str(value: &'static str) -> Self { - value + Cow::Borrowed(value) } } @@ -117,11 +117,11 @@ impl DeserializableTraceData for BytesData { } } -/// TraceData implementation using `&str` and `&[u8]`. +/// TraceData implementation using `Cow<'a, str>` and `&[u8]`. #[derive(Clone, Default, Debug, PartialEq, Serialize)] pub struct SliceData<'a>(PhantomData<&'a u8>); impl<'a> TraceData for SliceData<'a> { - type Text = &'a str; + type Text = Cow<'a, str>; type Bytes = &'a [u8]; } @@ -139,10 +139,10 @@ impl<'a> DeserializableTraceData for SliceData<'a> { } #[inline] - fn read_string(buf: &mut &'a [u8]) -> Result<&'a str, DecodeError> { + fn read_string(buf: &mut &'a [u8]) -> Result, DecodeError> { read_string_ref_nomut(buf).map(|(str, newbuf)| { *buf = newbuf; - str + Cow::Borrowed(str) }) } } diff --git a/libdd-trace-utils/src/span/v04/mod.rs b/libdd-trace-utils/src/span/v04/mod.rs index 54edc57ee7..0797501f80 100644 --- a/libdd-trace-utils/src/span/v04/mod.rs +++ b/libdd-trace-utils/src/span/v04/mod.rs @@ -327,6 +327,7 @@ mod tests { use crate::msgpack_decoder::decode::buffer::Buffer; use crate::msgpack_decoder::v04::span::decode_span; use crate::span::SliceData; + use std::borrow::Cow; use std::collections::HashMap; #[test] @@ -340,42 +341,50 @@ mod tests { #[test] fn serialize_deserialize_test() { let span: Span> = Span { - name: "tracing.operation", - resource: "MyEndpoint", + name: "tracing.operation".into(), + resource: "MyEndpoint".into(), span_links: vec![SpanLink { trace_id: 42, - attributes: HashMap::from([("span", "link")]), - tracestate: "running", + attributes: HashMap::from([("span".into(), "link".into())]), + tracestate: "running".into(), ..Default::default() }], span_events: vec![SpanEvent { time_unix_nano: 1727211691770716000, - name: "exception", + name: "exception".into(), attributes: HashMap::from([ ( - "exception.message", + "exception.message".into(), AttributeAnyValue::SingleValue(AttributeArrayValue::String( - "Cannot divide by zero", + "Cannot divide by zero".into(), )), ), ( - "exception.type", - AttributeAnyValue::SingleValue(AttributeArrayValue::String("RuntimeError")), + "exception.type".into(), + AttributeAnyValue::SingleValue(AttributeArrayValue::String( + "RuntimeError".into(), + )), ), ( - "exception.escaped", + "exception.escaped".into(), AttributeAnyValue::SingleValue(AttributeArrayValue::Boolean(false)), ), ( - "exception.count", + "exception.count".into(), AttributeAnyValue::SingleValue(AttributeArrayValue::Integer(1)), ), ( - "exception.lines", + "exception.lines".into(), AttributeAnyValue::Array(vec![ - AttributeArrayValue::String(" File \"\", line 1, in "), - AttributeArrayValue::String(" File \"\", line 1, in divide"), - AttributeArrayValue::String("RuntimeError: Cannot divide by zero"), + AttributeArrayValue::String(Cow::Borrowed( + " File \"\", line 1, in ", + )), + AttributeArrayValue::String(Cow::Borrowed( + " File \"\", line 1, in divide", + )), + AttributeArrayValue::String(Cow::Borrowed( + "RuntimeError: Cannot divide by zero", + )), ]), ), ]), @@ -416,9 +425,9 @@ mod tests { let span: Span> = Span { span_events: vec![SpanEvent { time_unix_nano: 1727211691770716000, - name: "test", + name: "test".into(), attributes: HashMap::from([( - "test.event", + "test.event".into(), AttributeAnyValue::SingleValue(AttributeArrayValue::Double(4.2)), )]), }], From 6988eb73c25654294da31753feb5376e2dd63460 Mon Sep 17 00:00:00 2001 From: vianney Date: Mon, 18 May 2026 20:45:40 +0200 Subject: [PATCH 2/6] remove uneeded cow --- libdd-trace-utils/src/span/v04/mod.rs | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/libdd-trace-utils/src/span/v04/mod.rs b/libdd-trace-utils/src/span/v04/mod.rs index 0797501f80..43da3dfcb8 100644 --- a/libdd-trace-utils/src/span/v04/mod.rs +++ b/libdd-trace-utils/src/span/v04/mod.rs @@ -327,7 +327,6 @@ mod tests { use crate::msgpack_decoder::decode::buffer::Buffer; use crate::msgpack_decoder::v04::span::decode_span; use crate::span::SliceData; - use std::borrow::Cow; use std::collections::HashMap; #[test] @@ -376,15 +375,15 @@ mod tests { ( "exception.lines".into(), AttributeAnyValue::Array(vec![ - AttributeArrayValue::String(Cow::Borrowed( - " File \"\", line 1, in ", - )), - AttributeArrayValue::String(Cow::Borrowed( - " File \"\", line 1, in divide", - )), - AttributeArrayValue::String(Cow::Borrowed( - "RuntimeError: Cannot divide by zero", - )), + AttributeArrayValue::String( + " File \"\", line 1, in ".into(), + ), + AttributeArrayValue::String( + " File \"\", line 1, in divide".into(), + ), + AttributeArrayValue::String( + "RuntimeError: Cannot divide by zero".into(), + ), ]), ), ]), From acf968d6fe8779663701a855509504f061394063 Mon Sep 17 00:00:00 2001 From: vianney Date: Mon, 18 May 2026 21:11:02 +0200 Subject: [PATCH 3/6] benchmarks(sampling): use convert str to cow --- libdd-sampling/benches/sampling_bench.rs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/libdd-sampling/benches/sampling_bench.rs b/libdd-sampling/benches/sampling_bench.rs index 1f08aede21..8971168411 100644 --- a/libdd-sampling/benches/sampling_bench.rs +++ b/libdd-sampling/benches/sampling_bench.rs @@ -31,9 +31,9 @@ fn make_span( resource: &'static str, ) -> Span> { Span { - name, - service, - resource, + name: name.into(), + service: service.into(), + resource: resource.into(), trace_id: 0x1234_5678_9012_3456_7890_1234_5678_9012_u128, ..Default::default() } @@ -170,7 +170,7 @@ fn make_configs() -> Vec { // 9. Tag rule — matching { let mut span = make_span("test-operation", "my-service", "test"); - span.meta.insert("environment", "production"); + span.meta.insert("environment".into(), "production".into()); BenchConfig { name: "tag_rule_matching", sampler: DatadogSampler::new( @@ -194,7 +194,7 @@ fn make_configs() -> Vec { // 10. Tag rule — not matching { let mut span = make_span("test-operation", "my-service", "test"); - span.meta.insert("environment", "staging"); + span.meta.insert("environment".into(), "staging".into()); BenchConfig { name: "tag_rule_not_matching", sampler: DatadogSampler::new( @@ -218,9 +218,9 @@ fn make_configs() -> Vec { // 11. Complex rule — all fields matching { let mut span = make_span("http.request", "api-service", "/api/v1/users"); - span.meta.insert("environment", "production"); - span.meta.insert("http.method", "POST"); - span.meta.insert("http.route", "/api/v1/users"); + span.meta.insert("environment".into(), "production".into()); + span.meta.insert("http.method".into(), "POST".into()); + span.meta.insert("http.route".into(), "/api/v1/users".into()); BenchConfig { name: "complex_rule_matching", sampler: DatadogSampler::new( @@ -244,9 +244,9 @@ fn make_configs() -> Vec { // 12. Complex rule — partial match (resource doesn't match) { let mut span = make_span("http.request", "api-service", "/health"); - span.meta.insert("environment", "staging"); - span.meta.insert("http.method", "POST"); - span.meta.insert("http.route", "/health"); + span.meta.insert("environment".into(), "staging".into()); + span.meta.insert("http.method".into(), "POST".into()); + span.meta.insert("http.route".into(), "/health".into()); BenchConfig { name: "complex_rule_partial_match", sampler: DatadogSampler::new( @@ -299,7 +299,7 @@ fn make_configs() -> Vec { { let mut span = make_span("test-operation", "my-service", "test"); for (k, v) in MANY_ATTR_PAIRS { - span.meta.insert(k, v); + span.meta.insert((*k).into(), (*v).into()); } BenchConfig { name: "many_attributes_tag_rule", From 271bedb539f7798987e694be11c456751b648ac8 Mon Sep 17 00:00:00 2001 From: vianney Date: Tue, 19 May 2026 11:42:26 +0200 Subject: [PATCH 4/6] test(sampling): wrap str --- libdd-sampling/src/v04_span.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libdd-sampling/src/v04_span.rs b/libdd-sampling/src/v04_span.rs index da738af138..77a74f6ee8 100644 --- a/libdd-sampling/src/v04_span.rs +++ b/libdd-sampling/src/v04_span.rs @@ -17,8 +17,8 @@ //! use libdd_trace_utils::span::{v04::Span, SliceData}; //! //! let mut span = Span::>::default(); -//! span.name = "my-operation"; -//! span.service = "my-service"; +//! span.name = "my-operation".into(); +//! span.service = "my-service".into(); //! span.trace_id = 1234567890u128; //! //! let sampler = DatadogSampler::new(vec![], 100); From d1cf282b01fd92842854d91121491b3114a0aa12 Mon Sep 17 00:00:00 2001 From: vianney Date: Tue, 19 May 2026 14:22:11 +0200 Subject: [PATCH 5/6] fix: conver str to cow --- libdd-sampling/benches/sampling_bench.rs | 3 ++- libdd-sampling/src/v04_span.rs | 25 ++++++++++++------------ 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/libdd-sampling/benches/sampling_bench.rs b/libdd-sampling/benches/sampling_bench.rs index 8971168411..f50480d9b9 100644 --- a/libdd-sampling/benches/sampling_bench.rs +++ b/libdd-sampling/benches/sampling_bench.rs @@ -220,7 +220,8 @@ fn make_configs() -> Vec { let mut span = make_span("http.request", "api-service", "/api/v1/users"); span.meta.insert("environment".into(), "production".into()); span.meta.insert("http.method".into(), "POST".into()); - span.meta.insert("http.route".into(), "/api/v1/users".into()); + span.meta + .insert("http.route".into(), "/api/v1/users".into()); BenchConfig { name: "complex_rule_matching", sampler: DatadogSampler::new( diff --git a/libdd-sampling/src/v04_span.rs b/libdd-sampling/src/v04_span.rs index 77a74f6ee8..6b4ca0d2e8 100644 --- a/libdd-sampling/src/v04_span.rs +++ b/libdd-sampling/src/v04_span.rs @@ -260,9 +260,9 @@ mod tests { resource: &'static str, ) -> Span> { Span { - name, - service, - resource, + name: name.into(), + service: service.into(), + resource: resource.into(), ..Default::default() } } @@ -324,8 +324,9 @@ mod tests { #[test] fn test_v04_span_properties_with_meta() { let mut span = make_span("op", "svc", "res"); - span.meta.insert("env", "staging"); - span.meta.insert("http.url", "https://example.com"); + span.meta.insert("env".into(), "staging".into()); + span.meta + .insert("http.url".into(), "https://example.com".into()); let props = V04SpanProperties::from_span(&span); assert_eq!(props.env(), "staging"); @@ -338,7 +339,7 @@ mod tests { #[test] fn test_v04_span_properties_status_code_from_metrics() { let mut span = make_span("op", "svc", "res"); - span.metrics.insert("http.status_code", 200.0); + span.metrics.insert("http.status_code".into(), 200.0); let props = V04SpanProperties::from_span(&span); assert_eq!(props.status_code(), Some(200)); @@ -348,7 +349,7 @@ mod tests { #[test] fn test_v04_span_properties_status_code_from_meta() { let mut span = make_span("op", "svc", "res"); - span.meta.insert("http.status_code", "404"); + span.meta.insert("http.status_code".into(), "404".into()); let props = V04SpanProperties::from_span(&span); assert_eq!(props.status_code(), Some(404)); @@ -357,7 +358,7 @@ mod tests { #[test] fn test_v04_span_properties_metrics_in_attributes() { let mut span = make_span("op", "svc", "res"); - span.metrics.insert("_sampling_priority_v1", 1.0); + span.metrics.insert("_sampling_priority_v1".into(), 1.0); let props = V04SpanProperties::from_span(&span); let attr = props @@ -398,7 +399,7 @@ mod tests { // compiler resolves correctly. let sampler = DatadogSampler::new(vec![], 100); let mut span = make_span("op", "my-service", "my-resource"); - span.meta.insert("env", "prod"); + span.meta.insert("env".into(), "prod".into()); let data = V04SamplingData { is_parent_sampled: None, span: &span, @@ -516,8 +517,8 @@ mod tests { fn test_integration_tags_apply_to_span() { let sampler = DatadogSampler::new(vec![], 100); let span = Span::> { - name: "op", - service: "svc", + name: "op".into(), + service: "svc".into(), ..Default::default() }; @@ -538,7 +539,7 @@ mod tests { assert!(!value.is_empty()); } V04SamplingTag::Metric { key, value } => { - out_span.metrics.insert(key, value); + out_span.metrics.insert(key.into(), value); } } } From 3f09f0b37e0a0cf1659a9de87fbfe8ff3971eec1 Mon Sep 17 00:00:00 2001 From: vianney Date: Tue, 19 May 2026 18:08:06 +0200 Subject: [PATCH 6/6] fix doc tests --- libdd-trace-utils/src/msgpack_encoder/v04/mod.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libdd-trace-utils/src/msgpack_encoder/v04/mod.rs b/libdd-trace-utils/src/msgpack_encoder/v04/mod.rs index 97cf222268..f0d5c01a88 100644 --- a/libdd-trace-utils/src/msgpack_encoder/v04/mod.rs +++ b/libdd-trace-utils/src/msgpack_encoder/v04/mod.rs @@ -49,7 +49,7 @@ fn to_writer]>>( /// /// let mut buffer = vec![0u8; 1024]; /// let span = SpanSlice { -/// name: "test-span", +/// name: "test-span".into(), /// ..Default::default() /// }; /// let traces = vec![vec![span]]; @@ -80,7 +80,7 @@ pub fn write_to_slice]>>( /// use libdd_trace_utils::span::v04::SpanSlice; /// /// let span = SpanSlice { -/// name: "test-span", +/// name: "test-span".into(), /// ..Default::default() /// }; /// let traces = vec![vec![span]]; @@ -110,7 +110,7 @@ pub fn to_vec]>>(traces: &[S]) -> Vec { /// use libdd_trace_utils::span::v04::SpanSlice; /// /// let span = SpanSlice { -/// name: "test-span", +/// name: "test-span".into(), /// ..Default::default() /// }; /// let traces = vec![vec![span]]; @@ -169,7 +169,7 @@ impl std::io::Write for CountLength { /// use libdd_trace_utils::span::v04::SpanSlice; /// /// let span = SpanSlice { -/// name: "test-span", +/// name: "test-span".into(), /// ..Default::default() /// }; /// let traces = vec![vec![span]];