Skip to content

[SVLS-8734] fix(traces): restore _dd.compute_stats to span meta to fix missing trace stats#1172

Closed
lym953 wants to merge 9 commits intomainfrom
yiming.luo/fix-missing-trace-stats
Closed

[SVLS-8734] fix(traces): restore _dd.compute_stats to span meta to fix missing trace stats#1172
lym953 wants to merge 9 commits intomainfrom
yiming.luo/fix-missing-trace-stats

Conversation

@lym953
Copy link
Copy Markdown
Contributor

@lym953 lym953 commented Apr 7, 2026

Problem

PR #1118 (SVLS-8734) moved _dd.compute_stats from each span's meta
field to the payload-level tracer_payload.tags map only. This caused
trace stats such as trace.aws.lambda.hits to disappear from the trace explorer.

The observed debug log that surfaced the issue:

Fix

Test plan

Automated tests

cargo test --lib traces::trace_processor

All 17 tests pass, including all 4 test_compute_stats_tag_* variants.

Manual tests

Test 1: Missing trace stats issue is fixed

Steps
  1. Deployed a Lambda function with Python 3.14 runtime
  2. Do not set env var DD_COMPUTE_TRACE_STATS_ON_EXTENSION or DD_TRACE_STATS_COMPUTATION_ENABLED
  3. Invoke it
Result

In Metrics Explorer, trace.aws.lambda.hits shows 1 hit.

Test 2: Duplicate trace stats issue is still fixed

Steps
  1. Deploy a Lambda function that uses github.com/DataDog/dd-trace-go/v2 v2.6.0
  2. Set env var:
    1. DD_TRACE_STATS_COMPUTATION_ENABLED: true, which turns on client-side stats
    2. DD_COMPUTE_TRACE_STATS_ON_EXTENSION: true, which tries to turn on extension side stats
  3. Invoke it
Result

Still only 1 hit with resource_name=dd-tracer-serverless-span, which means the double counting that #1118 was trying to fix is still fixed.
image

Next steps

Once serverless-e2e-tests deployment is fixed, run the e2e tests and ensure trace stats look good.

lym953 and others added 4 commits April 7, 2026 13:52
…ace.aws.lambda.hits

PR #1118 moved `_dd.compute_stats` from each span's `meta` (applied via
`get_tags_map()` / `ChunkProcessor`) to the payload-level `tracer_payload.tags`
only. The Datadog APM backend reads this signal from the root span's `meta`
field, not from the payload-level tags, so it stopped computing stats and
`trace.aws.lambda.hits` disappeared from the trace explorer.

Fix: propagate `_dd.compute_stats` to every span's `meta` in the same loop
that writes it to `tracer_payload.tags`, restoring the pre-#1118 behavior
while keeping the payload-level tag as well.

Also add debug logging to `handle_traces` to surface the header tags on
every incoming trace request, which aids diagnosing similar issues.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…n span meta

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…om payload tags

- Add `compute_stats_value` field to `ChunkProcessor` so the tag is set
  on each span's meta alongside the other function tags, instead of in a
  separate post-processing loop.
- Remove `_dd.compute_stats` from `tracer_payload.tags`: it was never set
  there before PR #1118 and is not needed — stats work via the span meta
  path alone.
- Compute and log the value once at the top of `process_traces`, before
  constructing `ChunkProcessor`.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@lym953 lym953 changed the title fix(traces): restore _dd.compute_stats on span meta to fix missing trace.aws.lambda.hits fix(traces): restore _dd.compute_stats to span meta to fix missing trace stats Apr 7, 2026
lym953 and others added 5 commits April 7, 2026 14:30
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ad of pre-computed value

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…bda_span to check span meta

_dd.compute_stats is now set on span meta instead of payload tags.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@lym953 lym953 changed the title fix(traces): restore _dd.compute_stats to span meta to fix missing trace stats [SVLS-8734] fix(traces): restore _dd.compute_stats to span meta to fix missing trace stats Apr 7, 2026
@lym953 lym953 marked this pull request as ready for review April 7, 2026 21:18
@lym953 lym953 requested a review from a team as a code owner April 7, 2026 21:18
@lym953 lym953 requested review from Copilot and duncanista April 7, 2026 21:18
Copy link
Copy Markdown
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

This PR fixes the missing trace stats issue by restoring _dd.compute_stats to span metadata. PR #1118 had moved this tag to payload-level tags, but the backend expects it on individual spans to properly calculate trace statistics.

Changes:

  • Move _dd.compute_stats back into individual span's meta field (previously moved to payload tags in PR #1118)
  • Add client_computed_stats: bool field to ChunkProcessor to track whether client has already computed stats
  • Remove _dd.compute_stats from tracer_payload.tags where it was incorrectly placed
  • Update tests to verify the tag is set on spans, not on payload level

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
bottlecap/src/traces/trace_processor.rs Moves _dd.compute_stats logic to ChunkProcessor::process() to set it on each span's meta based on both compute_trace_stats_on_extension and client_computed_stats config, removes the incorrect payload-level tag setting, and updates all related tests
bottlecap/src/lifecycle/invocation/processor.rs Updates test assertions to verify _dd.compute_stats is in span metadata rather than payload tags

@lym953
Copy link
Copy Markdown
Contributor Author

lym953 commented Apr 8, 2026

Aborting because stats don't work for Go and Java:
image

From @purple4reina ,

@lym953 lym953 closed this Apr 8, 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.

3 participants