Skip to content

fix: align Datadog-Client-Computed-Stats header with agent stats computation gate#3815

Merged
Leiyks merged 1 commit intomasterfrom
leiyks/fix-ci-stats-header-regression
Apr 23, 2026
Merged

fix: align Datadog-Client-Computed-Stats header with agent stats computation gate#3815
Leiyks merged 1 commit intomasterfrom
leiyks/fix-ci-stats-header-regression

Conversation

@Leiyks
Copy link
Copy Markdown
Contributor

@Leiyks Leiyks commented Apr 23, 2026

Problem

Commit 68e11c7 ("Check for agent version in client side stats") added ddog_agent_has_stats_computation() as a gate in serializer.c to suppress stats computation when the agent doesn't report client_drop_p0s: true. However, the Datadog-Client-Computed-Stats: true HTTP header — sent with every trace payload — was not updated in two other locations:

  • ext/coms.c (legacy background sender path)
  • ext/auto_flush.c (sidecar sender path)

Both still check only DD_TRACE_STATS_COMPUTATION_ENABLED (an INI flag), so the header is sent as true even when the agent gate would suppress actual stats computation. The system test TRACE_STATS_COMPUTATION_CLIENT_DROP_P0S_FALSE fails on every CI pipeline as a result.

Fix

Replace get_global_DD_TRACE_STATS_COMPUTATION_ENABLED() / get_DD_TRACE_STATS_COMPUTATION_ENABLED() with ddog_agent_has_stats_computation() in both locations, making the header consistent with the serializer gate.

Also adds #include <components-rs/ddtrace.h> to ext/auto_flush.c where the declaration was not yet visible.

Test

System test: TRACE_STATS_COMPUTATION_CLIENT_DROP_P0S_FALSE

…tats_computation gate

The header was still sent unconditionally based on the INI flag alone in
ext/coms.c and ext/auto_flush.c, while serializer.c already gates actual
stats computation on ddog_agent_has_stats_computation(). Add the same
agent-capability check to both header-emission sites so the header value
matches the serializer behaviour and the TRACE_STATS_COMPUTATION_CLIENT_DROP_P0S_FALSE
system test passes.
@datadog-prod-us1-5
Copy link
Copy Markdown

datadog-prod-us1-5 Bot commented Apr 23, 2026

Tests

🎉 All green!

❄️ No new flaky tests detected
🧪 All tests passed

🎯 Code Coverage (details)
Patch Coverage: 100.00%
Overall Coverage: 60.64% (-0.05%)

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

@Leiyks Leiyks marked this pull request as ready for review April 23, 2026 12:57
@Leiyks Leiyks requested a review from a team as a code owner April 23, 2026 12:57
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 509ad2e340

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread ext/coms.c
dd_append_header(&list, "Datadog-Meta-Lang-Version", php_version_rt.ptr, php_version_rt.len);
dd_append_header(&list, "Datadog-Meta-Tracer-Version", ZEND_STRL(PHP_DDTRACE_VERSION));
if (!get_global_DD_APM_TRACING_ENABLED() || (ddtrace_sidecar_for_signal && get_global_DD_TRACE_STATS_COMPUTATION_ENABLED())) {
if (!get_global_DD_APM_TRACING_ENABLED() || (ddtrace_sidecar_for_signal && get_global_DD_TRACE_STATS_COMPUTATION_ENABLED() && ddog_agent_has_stats_computation())) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Avoid freezing the stats header before agent info is ready

In background-sender mode with a sidecar present for telemetry/appsec, this header list is built once by ddtrace_coms_init_and_start_writer() during the first dd_rinit_once(), but dd_initialize_request() only calls ddtrace_agent_info_rinit()/ddtrace_apply_agent_info() later. At that point ddog_agent_has_stats_computation() is still false, so Datadog-Client-Computed-Stats is permanently omitted from the cached dd_agent_curl_headers even after agent info later enables stats and the serializer starts feeding the concentrator. This makes the legacy sender under-report the header for agents that do support client-side stats; the gate needs to be evaluated when per-request headers are assembled or after agent info is applied.

Useful? React with 👍 / 👎.

@Leiyks Leiyks merged commit 4b617c2 into master Apr 23, 2026
2100 of 2116 checks passed
@Leiyks Leiyks deleted the leiyks/fix-ci-stats-header-regression branch April 23, 2026 13:49
@github-actions github-actions Bot added this to the 1.19.0 milestone Apr 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants