Skip to content

feat(libdd-trace-utils): check for empty value in header datadog-client-computed-stats#1900

Merged
gh-worker-dd-mergequeue-cf854d[bot] merged 4 commits intomainfrom
duncan-harvey/datadog-client-computed-stats
Apr 22, 2026
Merged

feat(libdd-trace-utils): check for empty value in header datadog-client-computed-stats#1900
gh-worker-dd-mergequeue-cf854d[bot] merged 4 commits intomainfrom
duncan-harvey/datadog-client-computed-stats

Conversation

@duncanpharvey
Copy link
Copy Markdown
Contributor

@duncanpharvey duncanpharvey commented Apr 20, 2026

What does this PR do?

Treat an empty string as a falsy value for the Datadog-Client-Computed-Stats header.

Motivation

We want to support agent computed stats in the Serverless Compatibility Layer. Currently when the Datadog-Client-Computed-Stats header is sent it always disables agent computed stats, even when the value of the header is an empty string.

https://datadoghq.atlassian.net/browse/SVLS-8789

Additional Notes

How to test the change?

Added a debug log in a test build:

Before change with DD_TRACE_STATS_COMPUTATION_ENABLED=false

DEBUG datadog_trace_agent::trace_processor: Resolved tracer header tags: TracerHeaderTags { lang: "java", lang_version: "21.0.6", lang_interpreter: "OpenJDK 64-Bit Server VM", lang_vendor: "Microsoft", tracer_version: "1.61.1~e32291a78b", container_id: "", client_computed_top_level: true, client_computed_stats: true, dropped_p0_traces: 0, dropped_p0_spans: 0 }

After change with DD_TRACE_STATS_COMPUTATION_ENABLED=false

DEBUG datadog_trace_agent::trace_processor: Resolved tracer header tags: TracerHeaderTags { lang: "java", lang_version: "21.0.6", lang_interpreter: "OpenJDK 64-Bit Server VM", lang_vendor: "Microsoft", tracer_version: "1.61.1~e32291a78b", container_id: "", client_computed_top_level: true, client_computed_stats: false, dropped_p0_traces: 0, dropped_p0_spans: 0 }

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 20, 2026

Clippy Allow Annotation Report

Comparing clippy allow annotations between branches:

  • Base Branch: origin/main
  • PR Branch: origin/duncan-harvey/datadog-client-computed-stats

Summary by Rule

Rule Base Branch PR Branch Change

Annotation Counts by File

File Base Branch PR Branch Change

Annotation Stats by Crate

Crate Base Branch PR Branch Change
clippy-annotation-reporter 5 5 No change (0%)
datadog-ffe-ffi 1 1 No change (0%)
datadog-ipc 21 21 No change (0%)
datadog-live-debugger 6 6 No change (0%)
datadog-live-debugger-ffi 10 10 No change (0%)
datadog-profiling-replayer 4 4 No change (0%)
datadog-remote-config 3 3 No change (0%)
datadog-sidecar 56 56 No change (0%)
libdd-common 10 10 No change (0%)
libdd-common-ffi 12 12 No change (0%)
libdd-data-pipeline 5 5 No change (0%)
libdd-ddsketch 2 2 No change (0%)
libdd-dogstatsd-client 1 1 No change (0%)
libdd-profiling 13 13 No change (0%)
libdd-telemetry 19 19 No change (0%)
libdd-tinybytes 4 4 No change (0%)
libdd-trace-normalization 2 2 No change (0%)
libdd-trace-obfuscation 8 8 No change (0%)
libdd-trace-stats 1 1 No change (0%)
libdd-trace-utils 15 15 No change (0%)
Total 198 198 No change (0%)

About This Report

This report tracks Clippy allow annotations for specific rules, showing how they've changed in this PR. Decreasing the number of these annotations generally improves code quality.

@duncanpharvey duncanpharvey force-pushed the duncan-harvey/datadog-client-computed-stats branch from 0496440 to 17c3f1d Compare April 20, 2026 20:43
@datadog-prod-us1-4
Copy link
Copy Markdown

datadog-prod-us1-4 Bot commented Apr 20, 2026

Tests

🎉 All green!

❄️ No new flaky tests detected
🧪 All tests passed

🎯 Code Coverage (details)
Patch Coverage: 100.00%
Overall Coverage: 71.69% (-0.06%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: b2bcec9 | Docs | Datadog PR Page | Give us feedback!

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 20, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 71.68%. Comparing base (530cd96) to head (b2bcec9).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1900      +/-   ##
==========================================
- Coverage   71.74%   71.68%   -0.07%     
==========================================
  Files         434      434              
  Lines       69940    69954      +14     
==========================================
- Hits        50181    50147      -34     
- Misses      19759    19807      +48     
Components Coverage Δ
libdd-crashtracker 65.96% <ø> (+0.01%) ⬆️
libdd-crashtracker-ffi 34.09% <ø> (ø)
libdd-alloc 98.77% <ø> (ø)
libdd-data-pipeline 85.65% <ø> (ø)
libdd-data-pipeline-ffi 70.70% <ø> (ø)
libdd-common 79.41% <ø> (ø)
libdd-common-ffi 73.87% <ø> (ø)
libdd-telemetry 68.06% <ø> (ø)
libdd-telemetry-ffi 19.37% <ø> (ø)
libdd-dogstatsd-client 82.64% <ø> (ø)
datadog-ipc 74.84% <ø> (-1.43%) ⬇️
libdd-profiling 81.60% <ø> (-0.02%) ⬇️
libdd-profiling-ffi 64.36% <ø> (ø)
datadog-sidecar 29.11% <ø> (ø)
datdog-sidecar-ffi 7.20% <ø> (ø)
spawn-worker 54.69% <ø> (ø)
libdd-tinybytes 93.16% <ø> (ø)
libdd-trace-normalization 81.71% <ø> (ø)
libdd-trace-obfuscation 87.26% <ø> (ø)
libdd-trace-protobuf 68.25% <ø> (ø)
libdd-trace-utils 89.27% <100.00%> (+0.02%) ⬆️
datadog-tracer-flare 86.88% <ø> (ø)
libdd-log 74.69% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@dd-octo-sts
Copy link
Copy Markdown
Contributor

dd-octo-sts Bot commented Apr 20, 2026

Artifact Size Benchmark Report

aarch64-alpine-linux-musl
Artifact Baseline Commit Change
/aarch64-alpine-linux-musl/lib/libdatadog_profiling.a 83.34 MB 83.34 MB 0% (0 B) 👌
/aarch64-alpine-linux-musl/lib/libdatadog_profiling.so 7.63 MB 7.63 MB 0% (0 B) 👌
aarch64-unknown-linux-gnu
Artifact Baseline Commit Change
/aarch64-unknown-linux-gnu/lib/libdatadog_profiling.so 10.10 MB 10.10 MB 0% (0 B) 👌
/aarch64-unknown-linux-gnu/lib/libdatadog_profiling.a 99.41 MB 99.41 MB 0% (0 B) 👌
libdatadog-x64-windows
Artifact Baseline Commit Change
/libdatadog-x64-windows/debug/dynamic/datadog_profiling_ffi.dll 25.17 MB 25.17 MB 0% (0 B) 👌
/libdatadog-x64-windows/debug/dynamic/datadog_profiling_ffi.lib 79.90 KB 79.90 KB 0% (0 B) 👌
/libdatadog-x64-windows/debug/dynamic/datadog_profiling_ffi.pdb 184.42 MB 184.42 MB 0% (0 B) 👌
/libdatadog-x64-windows/debug/static/datadog_profiling_ffi.lib 918.36 MB 918.37 MB +0% (+1.15 KB) 👌
/libdatadog-x64-windows/release/dynamic/datadog_profiling_ffi.dll 7.89 MB 7.89 MB 0% (0 B) 👌
/libdatadog-x64-windows/release/dynamic/datadog_profiling_ffi.lib 79.90 KB 79.90 KB 0% (0 B) 👌
/libdatadog-x64-windows/release/dynamic/datadog_profiling_ffi.pdb 23.67 MB 23.67 MB 0% (0 B) 👌
/libdatadog-x64-windows/release/static/datadog_profiling_ffi.lib 46.19 MB 46.19 MB 0% (0 B) 👌
libdatadog-x86-windows
Artifact Baseline Commit Change
/libdatadog-x86-windows/debug/dynamic/datadog_profiling_ffi.dll 21.66 MB 21.66 MB 0% (0 B) 👌
/libdatadog-x86-windows/debug/dynamic/datadog_profiling_ffi.lib 81.14 KB 81.14 KB 0% (0 B) 👌
/libdatadog-x86-windows/debug/dynamic/datadog_profiling_ffi.pdb 188.54 MB 188.52 MB -0% (-16.00 KB) 👌
/libdatadog-x86-windows/debug/static/datadog_profiling_ffi.lib 903.78 MB 903.78 MB +0% (+1.05 KB) 👌
/libdatadog-x86-windows/release/dynamic/datadog_profiling_ffi.dll 6.13 MB 6.13 MB 0% (0 B) 👌
/libdatadog-x86-windows/release/dynamic/datadog_profiling_ffi.lib 81.14 KB 81.14 KB 0% (0 B) 👌
/libdatadog-x86-windows/release/dynamic/datadog_profiling_ffi.pdb 25.36 MB 25.36 MB 0% (0 B) 👌
/libdatadog-x86-windows/release/static/datadog_profiling_ffi.lib 43.67 MB 43.67 MB 0% (0 B) 👌
x86_64-alpine-linux-musl
Artifact Baseline Commit Change
/x86_64-alpine-linux-musl/lib/libdatadog_profiling.a 74.43 MB 74.43 MB 0% (0 B) 👌
/x86_64-alpine-linux-musl/lib/libdatadog_profiling.so 8.52 MB 8.52 MB 0% (0 B) 👌
x86_64-unknown-linux-gnu
Artifact Baseline Commit Change
/x86_64-unknown-linux-gnu/lib/libdatadog_profiling.a 91.78 MB 91.78 MB 0% (0 B) 👌
/x86_64-unknown-linux-gnu/lib/libdatadog_profiling.so 10.20 MB 10.20 MB 0% (0 B) 👌

@duncanpharvey duncanpharvey marked this pull request as ready for review April 21, 2026 14:59
@duncanpharvey duncanpharvey requested review from a team as code owners April 21, 2026 14:59
@duncanpharvey duncanpharvey requested review from a team, kathiehuang and lucaspimentel and removed request for a team April 21, 2026 14:59
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates libdd-trace-utils header parsing so that an explicitly empty Datadog-Client-Computed-Stats header value no longer disables agent-computed stats, enabling compatibility with tracers that send the header with an empty string (notably Java).

Changes:

  • Treat datadog-client-computed-stats: "" as falsy when converting from HeaderMap to TracerHeaderTags.
  • Add unit tests covering empty-string and absent-header cases for datadog-client-computed-stats.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 133 to 134
if headers.get("datadog-client-computed-top-level").is_some() {
tags.client_computed_top_level = true;
Copy link

Copilot AI Apr 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

datadog-client-computed-top-level is still treated as enabled solely by header presence (is_some()), so an explicitly empty header value (""), if sent, will set client_computed_top_level=true. This conflicts with the struct doc comment (“Any non-empty value will mean 'yes'”) and now differs from the datadog-client-computed-stats handling in the next lines. Consider parsing the value and requiring it to be non-empty (similar to client_computed_stats) to make the semantics consistent.

Suggested change
if headers.get("datadog-client-computed-top-level").is_some() {
tags.client_computed_top_level = true;
if let Some(v) = headers.get("datadog-client-computed-top-level") {
tags.client_computed_top_level = !is_header_empty(v.to_str().unwrap_or_default());

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The datadog-client-computed-top-level header is outside the scope of this change. Will leave this header handling as is until the need arises to change it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we still at least fix the struct doc (potentially in a separate PR? If the Codex assessment is true, contradicting doc and implementation can be confusing.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the TracerHeaderTags struct doc to accurately reflect the behavior of these fields:

// specifies that the client has marked top-level spans, when set. If the header is present
// this value will resolve to 'true'
pub client_computed_top_level: bool,
// specifies whether the client has computed stats so that the agent doesn't have to. If the
// header is present and is non-empty this value will resolve to 'true'
pub client_computed_stats: bool,

}
}

fn is_header_empty(value: &str) -> bool {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: I'm not sure it's worth making a bespoke function to just proxy str::is_empty

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough! I removed this function and check for the empty string directly:

if let Some(v) = headers.get("datadog-client-computed-stats") {
tags.client_computed_stats = !v.to_str().unwrap_or_default().is_empty();
}

Comment on lines +271 to +282
fn test_is_header_empty() {
// Empty string is true
assert!(is_header_empty(""));

// Truthy and arbitrary non-empty values are false
for val in &["1", "t", "T", "TRUE", "True", "true"] {
assert!(
!is_header_empty(val),
"expected is_header_empty({val:?}) to be false"
);
}
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: we're basically testing the implementation of std::str::is_empty here. I'm a bit skeptical about the value of doing this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed this test, see #1900 (comment)

@duncanpharvey
Copy link
Copy Markdown
Contributor Author

/merge

@gh-worker-devflow-routing-ef8351
Copy link
Copy Markdown

gh-worker-devflow-routing-ef8351 Bot commented Apr 22, 2026

View all feedbacks in Devflow UI.

2026-04-22 14:47:46 UTC ℹ️ Start processing command /merge


2026-04-22 14:47:51 UTC ℹ️ MergeQueue: pull request added to the queue

The expected merge time in main is approximately 43m (p90).


2026-04-22 15:56:35 UTCMergeQueue: The checks failed on this merge request

Tests failed on this commit 5345da5:

What to do next?

  • Investigate the failures and when ready, re-add your pull request to the queue!
  • If your PR checks are green, try to rebase/merge. It might be because the CI run is a bit old.
  • Any question, go check the FAQ.

@duncanpharvey
Copy link
Copy Markdown
Contributor Author

/merge

@gh-worker-devflow-routing-ef8351
Copy link
Copy Markdown

gh-worker-devflow-routing-ef8351 Bot commented Apr 22, 2026

View all feedbacks in Devflow UI.

2026-04-22 16:29:32 UTC ℹ️ Start processing command /merge


2026-04-22 16:29:40 UTC ℹ️ MergeQueue: waiting for PR to be ready

This pull request is not mergeable according to GitHub. Common reasons include pending required checks, missing approvals, or merge conflicts — but it could also be blocked by other repository rules or settings.
It will be added to the queue as soon as checks pass and/or get approvals. View in MergeQueue UI.
Note: if you pushed new commits since the last approval, you may need additional approval.
You can remove it from the waiting list with /remove command.


2026-04-22 17:00:09 UTC ℹ️ MergeQueue: merge request added to the queue

The expected merge time in main is approximately 43m (p90).


2026-04-22 17:32:55 UTC ℹ️ MergeQueue: This merge request was merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants