Skip to content

Commit cad01da

Browse files
committed
fix(traces): keep backend as safety net for trace stats when tracer claims client-computed-stats
The Datadog-Client-Computed-Stats header should only suppress extension-side stats generation, not backend stats. When the extension is not computing stats itself, always set _dd.compute_stats:1 so the backend remains a fallback.
1 parent 4fa65a9 commit cad01da

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

bottlecap/src/traces/trace_processor.rs

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -351,14 +351,17 @@ impl TraceProcessor for ServerlessTraceProcessor {
351351
for tracer_payload in collection.iter_mut() {
352352
tracer_payload.tags.extend(tags.clone());
353353
// Tell the backend whether to compute stats:
354-
// - "1" (compute on backend) if neither the tracer nor the extension is computing them
355-
// - "0" (skip on backend) if the extension or the tracer has already computed them
356-
let compute_stats = if !config.compute_trace_stats_on_extension
357-
&& !header_tags.client_computed_stats
358-
{
359-
"1"
360-
} else {
354+
// - "1" (compute on backend) if the extension is NOT computing stats
355+
// - "0" (skip on backend) if the extension is computing stats
356+
//
357+
// We intentionally ignore client_computed_stats here to keep
358+
// the backend as a safety net. If the tracer claims it computed
359+
// stats but they don't actually reach the backend, setting this
360+
// to "0" would cause stats to disappear entirely.
361+
let compute_stats = if config.compute_trace_stats_on_extension {
361362
"0"
363+
} else {
364+
"1"
362365
};
363366
tracer_payload
364367
.tags
@@ -1400,7 +1403,7 @@ mod tests {
14001403
/// | Input: `compute_trace_stats_on_extension` | Input: `client_computed_stats` | Expected: `_dd.compute_stats` | Expected: Extension generates stats? |
14011404
/// |-------------------------------------------|--------------------------------|-------------------------------|--------------------------------------|
14021405
/// | `false` | `false` | `"1"` | No |
1403-
/// | `false` | `true` | `"0"` | No |
1406+
/// | `false` | `true` | `"1"` | No |
14041407
/// | `true` | `false` | `"0"` | Yes |
14051408
/// | `true` | `true` | `"0"` | No |
14061409
#[allow(clippy::unwrap_used)]
@@ -1414,11 +1417,12 @@ mod tests {
14141417
use libdd_trace_obfuscation::obfuscation_config::ObfuscationConfig;
14151418
use tokio::sync::mpsc;
14161419

1417-
// "_dd.compute_stats" is "1" only when neither side computes stats (backend must do it).
1418-
let expected_tag = if !compute_trace_stats_on_extension && !client_computed_stats {
1419-
"1"
1420-
} else {
1420+
// "_dd.compute_stats" is "1" when the extension is NOT computing stats (backend must do it).
1421+
// client_computed_stats does NOT affect this tag — the backend is the safety net.
1422+
let expected_tag = if compute_trace_stats_on_extension {
14211423
"0"
1424+
} else {
1425+
"1"
14221426
};
14231427
// The extension generates stats only when it is configured to do so and the tracer hasn't.
14241428
let expect_stats = compute_trace_stats_on_extension && !client_computed_stats;
@@ -1529,7 +1533,8 @@ mod tests {
15291533
#[tokio::test]
15301534
#[allow(clippy::unwrap_used)]
15311535
async fn test_compute_stats_tag_tracer_computes() {
1532-
// Tracer computed stats (Datadog-Client-Computed-Stats header set) → tag "0".
1536+
// Tracer computed stats (Datadog-Client-Computed-Stats header set) → tag "1".
1537+
// Backend still computes as a safety net; extension skips its own stats generation.
15331538
check_compute_stats_behavior(false, true).await;
15341539
}
15351540

0 commit comments

Comments
 (0)