feat(traces): [SVLS-8734] respect Datadog-Client-Computed-Stats header#1118
feat(traces): [SVLS-8734] respect Datadog-Client-Computed-Stats header#1118
Conversation
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>
There was a problem hiding this comment.
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_statsis true, forces_dd.compute_statsto"0"in trace payload tags so backend stats computation is disabled. - Skips extension-side stats generation when
client_computed_statsis true, even ifDD_COMPUTE_TRACE_STATS_ON_EXTENSIONis enabled. - Makes
COMPUTE_STATS_KEYpub(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.
| /// 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] |
There was a problem hiding this comment.
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.
Background
traces/stats that go through Lambda extension can generate stats in three ways:
/v0.6/stats. Only works if the env varDD_TRACE_STATS_COMPUTATION_ENABLEDistrue.DD_COMPUTE_TRACE_STATS_ON_EXTENSIONis true._dd.compute_statsis1.If a trace has the header
Datadog-Client-Computed-Statswith a truthy value, then that means 1 is on, so we need to turn off 2 and 3 to avoid duplicate counts, i.e._dd.compute_statsto 0Summary
Datadog-Client-Computed-Statsheader is truthy, which means the tracer has already computed stats, the extension skips its own stats generation (turns off option 2)_dd.compute_statsto0in trace payload tags so the backend skips stats computation too (turns off option 3)COMPUTE_STATS_KEYpub(crate)so it can be referenced fromtrace_processorTest plan
Automated tests
Passed the new unit tests
Manual tests
Steps
github.com/DataDog/dd-trace-go/v2 v2.6.0DD_TRACE_STATS_COMPUTATION_ENABLED:true, which turns on 1DD_COMPUTE_TRACE_STATS_ON_EXTENSION:true, which tries to turn on 2Result
Before: 2 hits (duplicate), though with different

resource_nametagAfter: TODO
🤖 Generated with Claude Code