Skip to content

feat(traces): [SVLS-8734] respect Datadog-Client-Computed-Stats header#1118

Draft
lym953 wants to merge 4 commits intomainfrom
yiming.luo/ignore-tracer-stats
Draft

feat(traces): [SVLS-8734] respect Datadog-Client-Computed-Stats header#1118
lym953 wants to merge 4 commits intomainfrom
yiming.luo/ignore-tracer-stats

Conversation

@lym953
Copy link
Contributor

@lym953 lym953 commented Mar 20, 2026

Background

traces/stats that go through Lambda extension can generate stats in three ways:

  1. tracer generates stats and sends them to extension at /v0.6/stats. Only works if the env var DD_TRACE_STATS_COMPUTATION_ENABLED is true.
  2. extension generates stats from traces. It's off by default, and works only if env var DD_COMPUTE_TRACE_STATS_ON_EXTENSION is true.
  3. Datadog backend generates stats from traces. Works only if the trace tag _dd.compute_stats is 1.

If a trace has the header Datadog-Client-Computed-Stats with a truthy value, then that means 1 is on, so we need to turn off 2 and 3 to avoid duplicate counts, i.e.

  1. make extension not generate stats
  2. set trace tag _dd.compute_stats to 0

Summary

  • When the Datadog-Client-Computed-Stats header is truthy, which means the tracer has already computed stats, the extension skips its own stats generation (turns off option 2)
  • Also sets _dd.compute_stats to 0 in trace payload tags so the backend skips stats computation too (turns off option 3)
  • Made COMPUTE_STATS_KEY pub(crate) so it can be referenced from trace_processor

Test plan

Automated tests

Passed the new unit tests

Manual tests

Steps

  1. Deploy a Lambda function that uses github.com/DataDog/dd-trace-go/v2 v2.6.0
  2. Set env var:
  3. DD_TRACE_STATS_COMPUTATION_ENABLED: true, which turns on 1
  4. DD_COMPUTE_TRACE_STATS_ON_EXTENSION: true, which tries to turn on 2

Result

Before: 2 hits (duplicate), though with different resource_name tag
image

After: TODO

🤖 Generated with Claude Code

lym953 and others added 4 commits March 20, 2026 13:52
When the Datadog-Client-Computed-Stats header is set (truthy), the tracer
has already computed stats, so the extension should not double-count them.
This change:
- Skips extension-side stats generation when client_computed_stats is true
- Sets _dd.compute_stats to 0 in the trace payload tags so the backend
  also skips stats computation

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
… header is set

- Extended existing test to also assert that send_processed_traces does not
  generate stats when client_computed_stats is true
- Added new test covering the case where compute_trace_stats_on_extension is
  true but client_computed_stats is also true — no stats should be generated

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@lym953 lym953 changed the title feat(traces): respect Datadog-Client-Computed-Stats header feat(traces): [SVLS-8734] respect Datadog-Client-Computed-Stats header Mar 20, 2026
@lym953 lym953 marked this pull request as ready for review March 20, 2026 16:44
@lym953 lym953 requested a review from a team as a code owner March 20, 2026 16:44
@lym953 lym953 requested review from Copilot and shreyamalpani March 20, 2026 16:44
Copy link
Contributor

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

Updates the Lambda extension trace pipeline to respect the Datadog-Client-Computed-Stats header so stats are not double-computed (by the extension and/or backend) when the tracer already computed them.

Changes:

  • When client_computed_stats is true, forces _dd.compute_stats to "0" in trace payload tags so backend stats computation is disabled.
  • Skips extension-side stats generation when client_computed_stats is true, even if DD_COMPUTE_TRACE_STATS_ON_EXTENSION is enabled.
  • Makes COMPUTE_STATS_KEY pub(crate) and adds unit tests covering the new behavior.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
bottlecap/src/traces/trace_processor.rs Overrides _dd.compute_stats when the tracer computed stats; skips extension stats generation; adds tests.
bottlecap/src/tags/lambda/tags.rs Exposes COMPUTE_STATS_KEY within the crate for reuse.

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

Comment on lines +1384 to +1387
/// Verifies that when `client_computed_stats` is true, `process_traces` sets
/// `_dd.compute_stats` to "0" in the payload tags, overriding the value set by
/// `get_function_tags_map`, and that `send_processed_traces` does not generate stats.
#[tokio::test]
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

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

This test’s doc comment says it verifies send_processed_traces skips stats generation when client_computed_stats is true, but the config in this test has compute_trace_stats_on_extension: false, so stats generation is skipped regardless of the header. Consider removing the send_processed_traces portion here (the following test already covers the header-based skip), or adjust the setup so this test actually exercises the new condition.

Copilot uses AI. Check for mistakes.
@lym953 lym953 marked this pull request as draft March 20, 2026 17:01
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.

3 participants