Skip to content
Open
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
16 changes: 8 additions & 8 deletions libdd-data-pipeline/src/trace_exporter/trace_serializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,10 +290,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);
Expand Down Expand Up @@ -325,10 +325,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);
Expand Down
25 changes: 13 additions & 12 deletions libdd-sampling/benches/sampling_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ fn make_span(
resource: &'static str,
) -> Span<SliceData<'static>> {
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()
}
Expand Down Expand Up @@ -170,7 +170,7 @@ fn make_configs() -> Vec<BenchConfig> {
// 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(
Expand All @@ -194,7 +194,7 @@ fn make_configs() -> Vec<BenchConfig> {
// 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(
Expand All @@ -218,9 +218,10 @@ fn make_configs() -> Vec<BenchConfig> {
// 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(
Expand All @@ -244,9 +245,9 @@ fn make_configs() -> Vec<BenchConfig> {
// 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(
Expand Down Expand Up @@ -299,7 +300,7 @@ fn make_configs() -> Vec<BenchConfig> {
{
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",
Expand Down
29 changes: 15 additions & 14 deletions libdd-sampling/src/v04_span.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
//! use libdd_trace_utils::span::{v04::Span, SliceData};
//!
//! let mut span = Span::<SliceData<'_>>::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);
Expand Down Expand Up @@ -260,9 +260,9 @@ mod tests {
resource: &'static str,
) -> Span<SliceData<'static>> {
Span {
name,
service,
resource,
name: name.into(),
service: service.into(),
resource: resource.into(),
..Default::default()
}
}
Expand Down Expand Up @@ -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");
Expand All @@ -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));
Expand All @@ -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));
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -516,8 +517,8 @@ mod tests {
fn test_integration_tags_apply_to_span() {
let sampler = DatadogSampler::new(vec![], 100);
let span = Span::<SliceData<'static>> {
name: "op",
service: "svc",
name: "op".into(),
service: "svc".into(),
..Default::default()
};

Expand All @@ -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);
}
}
}
Expand Down
83 changes: 44 additions & 39 deletions libdd-trace-stats/src/span_concentrator/aggregation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -305,12 +304,9 @@ impl From<pb::ClientGroupedStats> for OwnedAggregationKey {
}

/// Return true if we care about peer tags on the span
fn should_track_peer_tags<T>(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"
)
}
Expand Down Expand Up @@ -878,12 +874,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 {
Expand All @@ -899,16 +898,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()
},
Expand All @@ -930,16 +929,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()
},
Expand Down Expand Up @@ -984,15 +983,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()
};
Expand All @@ -1011,14 +1010,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()
};
Expand All @@ -1035,12 +1037,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()];
Expand Down
Loading
Loading