Skip to content

[APMSVLS-469] fix(traces): filter sampled-out trace chunks when tracer or extension computes stats - #1358

Open
lucaspimentel wants to merge 2 commits into
mainfrom
lpimentel/filter-sampled-traces-by-stats-owner
Open

[APMSVLS-469] fix(traces): filter sampled-out trace chunks when tracer or extension computes stats#1358
lucaspimentel wants to merge 2 commits into
mainfrom
lpimentel/filter-sampled-traces-by-stats-owner

Conversation

@lucaspimentel

@lucaspimentel lucaspimentel commented Sep 4, 2026

Copy link
Copy Markdown
Member

Overview

Follow-up to #1320. Filters sampled-out trace chunks from trace intake whenever trace stats are computed before the backend, by either the tracer or the extension. Previously the filtering gate only checked lambda_extension_compute_stats, so tracers that compute stats themselves and report Datadog-Client-Computed-Stats: true (for example, dd-trace-java v1.63.0 with DD_TRACE_STATS_COMPUTATION_ENABLED on by default) still had their rejected chunks forwarded to intake.

Stats owner Sampled-out chunks sent to trace intake
Backend (lambda_extension_compute_stats=false, client_computed_stats=false) Yes, the backend needs them to compute stats
Extension (lambda_extension_compute_stats=true) No, filtered
Tracer (client_computed_stats=true) No, filtered

Behavior notes:

  • Stats-ownership precedence is unchanged: client_computed_stats=true means the tracer owns stats even when extension-side stats are also configured.
  • Within process_traces, stats ownership is resolved once and reused for both _dd.compute_stats stamping and sampled-out filtering, keeping those paths aligned.
  • Sampling priorities are never rewritten.
  • The pre-filter payload is still cloned before filtering, so extension-side stats include sampled-out traces.
  • The error sampler from [APMSVLS-469] feat(traces): add error sampler to keep/rescue traces with errors #1320 now also applies on the tracer-owned path, rescuing eligible errored AutoDrop chunks; explicit/user drops (negative priority) remain dropped, and _dd.errors_sr is stamped on rescued root spans.

Testing

  • Unit tests in trace_processor.rs: table-driven over all four ownership combinations, asserting filtering vs. no-filtering, the pre-filter stats payload contents, and error rescue on both non-backend paths. The tracer-owned case was confirmed failing before the fix.
  • Fake-intake E2E tests in apm_integration_test.rs: e2e_sampled_out_chunks_filtered_by_stats_owner (backend keeps all chunks; extension and tracer paths filter to the kept trace only) and e2e_error_sampler_rescues_only_errored_p0_traces extended to both non-backend owners.
  • cargo nextest run --workspace: 678 passed, 0 failed.
  • cargo fmt --all -- --check, cargo check --workspace, and both clippy passes (default and fips features) pass.

Found while investigating excess trace volume in the serverless-e2e-tests java17-sampling scenario: 20 traces observed at a 0.2 sample rate over 50 invocations where roughly 10 were expected.

…xtension computes stats

Trace intake now drops sampled-out chunks whenever stats are computed
before the backend, by either the tracer (Datadog-Client-Computed-Stats)
or the extension, instead of only when extension-side stats are enabled.
The backend still receives them when it owns stats computation, since it
needs them to compute stats. The error sampler now rescues eligible
errored drops on both non-backend paths.
@datadog-prod-us1-3

datadog-prod-us1-3 Bot commented Sep 4, 2026

Copy link
Copy Markdown

Pipelines

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 0cf9309 | Docs | View more details | Give us feedback!

@lucaspimentel lucaspimentel left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Found one high-severity trace-loss issue.


Review by Claude Code

Comment thread bottlecap/src/traces/trace_processor.rs
@lucaspimentel
lucaspimentel marked this pull request as ready for review September 8, 2026 13:54
Copilot AI lite review requested due to automatic review settings September 8, 2026 13:54
@lucaspimentel
lucaspimentel requested review from a team as code owners September 8, 2026 13:54
@lucaspimentel
lucaspimentel requested a review from lym953 September 8, 2026 13:54
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 8, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-08T13:59:01.396945Z b57d663 Draft marked ready
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Copilot AI left a comment

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.

🟢 Approval recommended

The change is narrowly scoped, aligns behavior with the documented stats-ownership matrix, and is backed by expanded unit + E2E test coverage for both extension-owned and tracer-owned paths.

Pull request overview

This PR updates Bottlecap’s trace intake filtering to drop sampled-out trace chunks whenever trace stats are computed before the backend—whether stats are computed by the extension or by the tracer—while preserving backend-owned behavior (keeping all chunks so the backend can compute stats). This aligns the filtering gate with the existing stats-ownership precedence (client_computed_stats overrides extension-side stats).

Changes:

  • Resolve stats ownership via StatsComputedBy::resolve(...) and filter sampled-out chunks whenever the backend does not own stats.
  • Extend unit tests and fake-intake E2E tests to cover tracer-owned stats paths (including error sampler behavior) in addition to extension-owned paths.
  • Update config/docs comments to reflect that error sampling/filtering applies on both extension-owned and tracer-owned stats paths.
File summaries
File Description
bottlecap/src/traces/trace_processor.rs Filters sampled-out chunks based on resolved stats owner (backend vs extension vs tracer) and expands unit tests to cover all ownership combinations.
bottlecap/tests/apm_integration_test.rs Extends fake-intake E2E coverage to validate filtering + error rescue behavior for both extension-owned and tracer-owned stats paths.
bottlecap/src/config/mod.rs Updates DD_SERVERLESS_ERROR_SAMPLER_ENABLED documentation to reflect applicability beyond extension-owned stats.
Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

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

Copy link
Copy Markdown

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: b57d663bc5

ℹ️ 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 bottlecap/src/traces/trace_processor.rs
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