Skip to content

feat(traces): Add error sampler, rescue errored p0 trace chunks - #169

Open
lucaspimentel wants to merge 9 commits into
mainfrom
lpimentel/add-error-sampler
Open

lucaspimentel wants to merge 9 commits into
mainfrom
lpimentel/add-error-sampler

Conversation

@lucaspimentel

@lucaspimentel lucaspimentel commented Sep 18, 2026 •

Copy link
Copy Markdown
Member

What does this PR do?

Wires the shared error sampler (datadog-agent-trace-sampler) into the SCL trace processor. Chunks with automatic-drop priority (0) containing a span with a non-zero error flag get a second look; on a keep, the sampler's rate is stamped as a positive _dd.errors_sr on the root span, which the backend treats as an error ingestion reason and retains without priority promotion. Chunks are not dropped locally (yet): unrescued P0 chunks are forwarded unchanged for the backend to discard. This will be done in a separate PR.

  • Defaults to RateLimited at 10 error TPS per process, one budget shared across requests and processor clones; AlwaysKeep available
  • Configured via DD_APM_ERROR_SAMPLER_MODE and DD_APM_ERROR_TPS (<= 0 disables rescue); invalid values warn and fall back to defaults
  • Runs after stats submission and before payload splitting, gated on agent_stats_computation_enabled; only the root's _dd.errors_sr is added, priorities and decision makers are untouched

Motivation

APMSVLS-472. Under tracer sampling, errored P0 chunks are discarded by the backend's ordinary P0 drop; a positive _dd.errors_sr is sufficient for the backend to bypass it.

Describe how to test/QA your changes

New config tests (env parsing, defaults, fallbacks), deterministic processor tests covering the full rescue matrix (compared against a standalone shared sampler), and an integration test that decodes the outbound protobuf payload and agent-computed stats. cargo check/clippy/fmt, cargo nextest run --workspace --no-fail-fast (429/430; the one failure is a pre-existing local port-8126 collision on main), and doc tests all pass.

@lucaspimentel

Copy link
Copy Markdown
Member Author

@DataDog review

@datadog-datadog-prod-us1-2 datadog-datadog-prod-us1-2 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.

Datadog Autotest: FAIL

Concurrent requests can send times to the shared sampler in reverse order at a bucket limit. This can clear valid counts and permit too many rescued traces.

Open Bits AI session

🤖 Datadog Autotest · Commit f316a2a · What is Autotest? · @DataDog review to ask questions · Any feedback? Reach out in #autotest

Comment thread crates/datadog-trace-agent/src/trace_processor.rs Outdated
@lucaspimentel

Copy link
Copy Markdown
Member Author

@DataDog review

@datadog-datadog-prod-us1-2 datadog-datadog-prod-us1-2 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.

Datadog Autotest: FAIL

A backward system-clock change can move the sampler to an old bucket. The sampler then uses stale counts and applies the TPS limit incorrectly.

Open Bits AI session

🤖 Datadog Autotest · Commit e5fcd5e · What is Autotest? · @DataDog review to ask questions · Any feedback? Reach out in #autotest

Comment thread crates/datadog-trace-agent/src/trace_processor.rs
Wire the shared datadog-agent-trace-sampler into the SCL trace
processor so error chunks with automatic-drop priority (0) get a
second look before being forwarded. On a keep, the sampler's rate is
stamped as a positive `_dd.errors_sr` metric on the chunk's root span,
which the APM backend treats as an `error` ingestion reason and retains
without any priority promotion. Chunks are never dropped locally:
unrescued chunks are forwarded unchanged for the backend to discard.

- Default to rate-limited rescue at 10 error TPS per process, with a
  shared budget across requests and processor clones
- Configure via DD_APM_ERROR_SAMPLER_MODE (rate_limited | always_keep)
  and DD_APM_ERROR_TPS (<= 0 disables rescue in either mode); invalid
  values warn and fall back to defaults
- Gate rescue on agent stats computation and submit all chunks to the
  stats concentrator before any rescue stamping
@lucaspimentel
lucaspimentel force-pushed the lpimentel/add-error-sampler branch from e5fcd5e to bfbe164 Compare September 24, 2026 15:07
@lucaspimentel lucaspimentel changed the title Rescue errored P0 trace chunks from backend drop feat(traces): Add error sampler, rescue errored p0 trace chunks Sep 24, 2026
@lucaspimentel
lucaspimentel marked this pull request as ready for review September 24, 2026 15:08
@lucaspimentel
lucaspimentel requested review from a team as code owners September 24, 2026 15:08
@lucaspimentel
lucaspimentel requested review from apiarian-datadog and lym953 and a lite review from Copilot and removed request for a team September 24, 2026 15:08
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 24, 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-24T15:13:01.693071Z bfbe164 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.

@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: bfbe16481b

ℹ️ 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 crates/datadog-trace-agent/src/trace_processor.rs

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.

Copilot review overview

🟡 Changes recommended

Moderate issues remain in sampler test equivalence, mutex contention, and integration-test error propagation.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 2 Medium severity · 1 Low severity

Open (3)
What changed in this PR

Adds shared error sampling to rescue eligible errored P0 trace chunks while preserving priorities and stats behavior.

Changes:

  • Integrates configurable, shared error sampling.
  • Stamps _dd.errors_sr on rescued root spans.
  • Adds configuration, dependency wiring, and unit/integration coverage.
File Review summary
crates/​datadog-trace-agent/​tests/​integration_test.rs Moderate findings (1 vote each): propagate mini-agent startup and shutdown/task errors.
crates/​datadog-trace-agent/​src/​trace_processor.rs Moderate findings: align test environments in sampler oracles (2 votes each); avoid holding a blocking mutex during the full payload walk (1 vote). Nit: document root-resolution fallback behavior (2 votes).
crates/​datadog-trace-agent/​src/​stats_processor.rs Test configuration fixtures updated; no findings.
crates/​datadog-trace-agent/​src/​config.rs Sampler configuration parsing updated; no findings.
crates/​datadog-trace-agent/​Cargo.toml Adds the sampler dependency; no findings.
crates/​datadog-serverless-compat/​src/​main.rs Initializes the shared sampler; no findings.
Cargo.lock Records dependency updates; no findings.

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

Comment thread crates/datadog-trace-agent/src/trace_processor.rs Outdated
Comment thread crates/datadog-trace-agent/src/trace_processor.rs Outdated
Comment thread crates/datadog-trace-agent/src/trace_processor.rs Outdated
Extracts the "prefer tracer payload env, fall back to agent config env"
rule into one function reused by stats flushing and error-rescue
sampling, and removes duplicated sampler lock/disabled-check and
SpanView-construction code in the error sampler and its tests.
The clock read and timestamp clamp were happening before the sampler
lock was acquired, letting concurrent requests deliver timestamps out
of lock-acquisition order and undercount TPS in the rolling window.
🤖

This branch has not been deployed

No deployments
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