Skip to content

Commit 2dc6e67

Browse files
authored
refactor(sampling)!: use sampling from libdatadog [APMSP-3021] (#154)
Moves the sampling code into a separate crate, and uses the moved sampling code from `libdatadog` DataDog/libdatadog#1927 These are the benchmark numbers after DataDog/libdatadog#1977 landed. ### OTel Sampling Benchmarks vs `main` #### Allocations | Benchmark | Allocated | Change | |---|---|---| | `rule_all_spans_only_rate` | 0.732 KB | ±0.0% (no change) | | `service_rule_matching` | 0.756 KB | **-92.1%** 🟢 | | `service_rule_not_matching` | 0.434 KB | -2.9% 🟢 | | `name_pattern_rule_matching` | 0.746 KB | **-92.2%** 🟢 | | `name_pattern_rule_not_matching` | 0.460 KB | -7.8% 🟢 | | `resource_pattern_rule_matching` | 0.502 KB | -7.2% 🟢 | | `resource_pattern_rule_not_matching` | 0.500 KB | -6.7% 🟢 | | `tag_rule_matching` | 1.021 KB | **-89.9%** 🟢 | | `tag_rule_not_matching` | 0.460 KB | -6.5% 🟢 | | `complex_rule_matching` | 0.477 KB | -9.1% 🟢 | | `complex_rule_partial_match` | 0.470 KB | -8.2% 🟢 | | `multiple_rules_first_match` | 0.756 KB | **-92.1%** 🟢 | | `multiple_rules_last_match` | 0.758 KB | -3.3% 🟢 | | `many_attributes` | 1.012 KB | **-90.0%** 🟢 | | `parent_sampled_short_circuit` | ~0 B | no change | | `parent_not_sampled_short_circuit` | ~0 B | no change | | `unicode_rule_matching` | 0.496 KB | ±0.0% (no change) | #### Wall Time | Benchmark | Time | Change | |---|---|---| | `rule_all_spans_only_rate` | 329 ns | -2.9% 🟢 | | `service_rule_matching` | 461 ns | -14.8% 🟢 | | `service_rule_not_matching` | 244 ns | -7.6% 🟢 | | `name_pattern_rule_matching` | 363 ns | -18.0% 🟢 | | `name_pattern_rule_not_matching` | 177 ns | -14.1% 🟢 | | `resource_pattern_rule_matching` | 252 ns | -11.0% 🟢 | | `resource_pattern_rule_not_matching` | 256 ns | -10.7% 🟢 | | `tag_rule_matching` | 386 ns | -17.5% 🟢 | | `tag_rule_not_matching` | 204 ns | -13.8% 🟢 | | `complex_rule_matching` | 386 ns | -10.9% 🟢 | | `complex_rule_partial_match` | 385 ns | -11.1% 🟢 | | `multiple_rules_first_match` | 376 ns | -17.6% 🟢 | | `multiple_rules_last_match` | 510 ns | -6.8% 🟢 | | `many_attributes` | 392 ns | -16.9% 🟢 | | `parent_sampled_short_circuit` | 9.2 ns | ~-0.8% (noise) | | `parent_not_sampled_short_circuit` | 9.2 ns | ~-0.7% (noise) | | `unicode_rule_matching` | 251 ns | -1.8% 🟢 | Co-authored-by: bjorn.antonsson <bjorn.antonsson@datadoghq.com>
1 parent 4e77aa6 commit 2dc6e67

25 files changed

Lines changed: 1332 additions & 3763 deletions

Cargo.lock

Lines changed: 750 additions & 439 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ libdd-telemetry = { version = "4.0.0", default-features = false }
2929
libdd-common = { version = "3.0.1", default-features = false }
3030
libdd-tinybytes = { version = "1.1.0", default-features = false }
3131
libdd-library-config = { version = "1.1.0", default-features = false }
32+
libdd-sampling = { version = "1.0.0", default-features = false }
3233
opentelemetry_sdk = { version = "0.31.0", features = [
3334
"trace",
3435
"metrics",

LICENSE-3rdparty.csv

Lines changed: 50 additions & 29 deletions
Large diffs are not rendered by default.

datadog-opentelemetry/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ rustdoc-args = ["--cfg", "docsrs"]
1515

1616

1717
[dependencies]
18-
1918
# External dependencies
2019
foldhash = { workspace = true }
2120
hashbrown = { workspace = true }
@@ -64,6 +63,7 @@ libdd-trace-utils = { workspace = true }
6463
libdd-telemetry = { workspace = true }
6564
libdd-common = { workspace = true }
6665
libdd-tinybytes = { workspace = true }
66+
libdd-sampling = { workspace = true }
6767
percent-encoding = "2.3.1"
6868

6969
[target.'cfg(target_os="linux")'.dependencies]

datadog-opentelemetry/benches/otel_sampling_benchmark.rs

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ fn create_benchmark_configs() -> Vec<BenchmarkConfig> {
6060
name: None,
6161
resource: None,
6262
tags: HashMap::new(),
63-
provenance: "".to_string(),
6463
}],
6564
resource: opentelemetry_sdk::Resource::builder_empty().build(),
6665
trace_id,
@@ -79,7 +78,6 @@ fn create_benchmark_configs() -> Vec<BenchmarkConfig> {
7978
name: None,
8079
resource: None,
8180
tags: HashMap::new(),
82-
provenance: "".to_string(),
8381
}],
8482
resource: opentelemetry_sdk::Resource::builder()
8583
.with_service_name("test-service")
@@ -100,7 +98,6 @@ fn create_benchmark_configs() -> Vec<BenchmarkConfig> {
10098
name: None,
10199
resource: None,
102100
tags: HashMap::new(),
103-
provenance: "".to_string(),
104101
}],
105102
resource: opentelemetry_sdk::Resource::builder()
106103
.with_service_name("other-service")
@@ -121,7 +118,6 @@ fn create_benchmark_configs() -> Vec<BenchmarkConfig> {
121118
name: Some("http.*".to_string()),
122119
resource: None,
123120
tags: HashMap::new(),
124-
provenance: "".to_string(),
125121
}],
126122
resource: opentelemetry_sdk::Resource::builder_empty().build(),
127123
trace_id,
@@ -140,7 +136,6 @@ fn create_benchmark_configs() -> Vec<BenchmarkConfig> {
140136
name: Some("http.*".to_string()),
141137
resource: None,
142138
tags: HashMap::new(),
143-
provenance: "".to_string(),
144139
}],
145140
resource: opentelemetry_sdk::Resource::builder_empty().build(),
146141
trace_id,
@@ -159,7 +154,6 @@ fn create_benchmark_configs() -> Vec<BenchmarkConfig> {
159154
name: None,
160155
resource: Some("/api/*".to_string()),
161156
tags: HashMap::new(),
162-
provenance: "".to_string(),
163157
}],
164158
resource: opentelemetry_sdk::Resource::builder_empty().build(),
165159
trace_id,
@@ -181,7 +175,6 @@ fn create_benchmark_configs() -> Vec<BenchmarkConfig> {
181175
name: None,
182176
resource: Some("/api/*".to_string()),
183177
tags: HashMap::new(),
184-
provenance: "".to_string(),
185178
}],
186179
resource: opentelemetry_sdk::Resource::builder_empty().build(),
187180
trace_id,
@@ -203,7 +196,6 @@ fn create_benchmark_configs() -> Vec<BenchmarkConfig> {
203196
name: None,
204197
resource: None,
205198
tags: HashMap::from([("environment".to_string(), "production".to_string())]),
206-
provenance: "".to_string(),
207199
}],
208200
resource: opentelemetry_sdk::Resource::builder_empty().build(),
209201
trace_id,
@@ -225,7 +217,6 @@ fn create_benchmark_configs() -> Vec<BenchmarkConfig> {
225217
name: None,
226218
resource: None,
227219
tags: HashMap::from([("environment".to_string(), "production".to_string())]),
228-
provenance: "".to_string(),
229220
}],
230221
resource: opentelemetry_sdk::Resource::builder_empty().build(),
231222
trace_id,
@@ -247,7 +238,6 @@ fn create_benchmark_configs() -> Vec<BenchmarkConfig> {
247238
name: Some("http.*".to_string()),
248239
resource: Some("/api/v1/*".to_string()),
249240
tags: HashMap::from([("environment".to_string(), "production".to_string())]),
250-
provenance: "".to_string(),
251241
}],
252242
resource: opentelemetry_sdk::Resource::builder()
253243
.with_service_name("api-service")
@@ -272,7 +262,6 @@ fn create_benchmark_configs() -> Vec<BenchmarkConfig> {
272262
name: Some("http.*".to_string()),
273263
resource: Some("/api/v1/*".to_string()),
274264
tags: HashMap::from([("environment".to_string(), "production".to_string())]),
275-
provenance: "".to_string(),
276265
}],
277266
resource: opentelemetry_sdk::Resource::builder()
278267
.with_service_name("api-service")
@@ -298,23 +287,20 @@ fn create_benchmark_configs() -> Vec<BenchmarkConfig> {
298287
name: None,
299288
resource: None,
300289
tags: HashMap::new(),
301-
provenance: "".to_string(),
302290
},
303291
SamplingRuleConfig {
304292
sample_rate: 0.5,
305293
service: Some("web-service".to_string()),
306294
name: None,
307295
resource: None,
308296
tags: HashMap::new(),
309-
provenance: "".to_string(),
310297
},
311298
SamplingRuleConfig {
312299
sample_rate: 1.0,
313300
service: None,
314301
name: None,
315302
resource: None,
316303
tags: HashMap::new(),
317-
provenance: "".to_string(),
318304
},
319305
],
320306
resource: opentelemetry_sdk::Resource::builder()
@@ -337,23 +323,20 @@ fn create_benchmark_configs() -> Vec<BenchmarkConfig> {
337323
name: None,
338324
resource: None,
339325
tags: HashMap::new(),
340-
provenance: "".to_string(),
341326
},
342327
SamplingRuleConfig {
343328
sample_rate: 0.5,
344329
service: Some("web-service".to_string()),
345330
name: None,
346331
resource: None,
347332
tags: HashMap::new(),
348-
provenance: "".to_string(),
349333
},
350334
SamplingRuleConfig {
351335
sample_rate: 1.0,
352336
service: None,
353337
name: None,
354338
resource: None,
355339
tags: HashMap::new(),
356-
provenance: "".to_string(),
357340
},
358341
],
359342
resource: opentelemetry_sdk::Resource::builder()
@@ -375,7 +358,6 @@ fn create_benchmark_configs() -> Vec<BenchmarkConfig> {
375358
name: None,
376359
resource: None,
377360
tags: HashMap::from([("key10".to_string(), "value10".to_string())]),
378-
provenance: "".to_string(),
379361
}],
380362
resource: opentelemetry_sdk::Resource::builder_empty().build(),
381363
trace_id,
@@ -400,7 +382,6 @@ fn create_benchmark_configs() -> Vec<BenchmarkConfig> {
400382
("region".to_string(), "us-east-1".to_string()),
401383
("version".to_string(), "v1.2.3".to_string()),
402384
]),
403-
provenance: "".to_string(),
404385
}],
405386
resource: opentelemetry_sdk::Resource::builder()
406387
.with_service_name("test-service")
@@ -414,7 +395,35 @@ fn create_benchmark_configs() -> Vec<BenchmarkConfig> {
414395
parent_context: Some(create_parent_context(true)),
415396
expected_decision: Some(SamplingDecision::RecordAndSample),
416397
},
417-
// 16. Parent not sampled - short circuit with many attributes and complex rules
398+
// 16. Unicode patterns - matching service, name, resource and tag values
399+
BenchmarkConfig {
400+
name: "unicode_rule_matching",
401+
rules: vec![SamplingRuleConfig {
402+
sample_rate: 1.0,
403+
service: Some("日本語-サービス".to_string()),
404+
name: Some("トレース.*".to_string()),
405+
resource: Some("/π/*/δοκιμή".to_string()),
406+
tags: HashMap::from([
407+
("environnement".to_string(), "prodüktion".to_string()),
408+
("emoji".to_string(), "🚀*".to_string()),
409+
]),
410+
}],
411+
resource: opentelemetry_sdk::Resource::builder()
412+
.with_service_name("日本語-サービス")
413+
.build(),
414+
trace_id,
415+
span_name: "トレース.リクエスト",
416+
span_kind: SpanKind::Server,
417+
attributes: vec![
418+
KeyValue::new("http.route", "/π/v1/δοκιμή"),
419+
KeyValue::new("environnement", "prodüktion"),
420+
KeyValue::new("emoji", "🚀launch"),
421+
KeyValue::new("description", "αβγδ ☃ 漢字 emoji 🎉"),
422+
],
423+
parent_context: None,
424+
expected_decision: Some(SamplingDecision::RecordAndSample),
425+
},
426+
// 17. Parent not sampled - short circuit with many attributes and complex rules
418427
BenchmarkConfig {
419428
name: "parent_not_sampled_short_circuit",
420429
rules: vec![SamplingRuleConfig {
@@ -427,7 +436,6 @@ fn create_benchmark_configs() -> Vec<BenchmarkConfig> {
427436
("region".to_string(), "us-east-1".to_string()),
428437
("version".to_string(), "v1.2.3".to_string()),
429438
]),
430-
provenance: "".to_string(),
431439
}],
432440
resource: opentelemetry_sdk::Resource::builder()
433441
.with_service_name("test-service")

0 commit comments

Comments
 (0)