Skip to content

[APMSVLS-469] Rate-limit error trace rescue with DD_APM_ERROR_TPS - #1490

Open
lucaspimentel wants to merge 15 commits into
mainfrom
lpimentel/error-sampler-rate-limited
Open

lucaspimentel wants to merge 15 commits into
mainfrom
lpimentel/error-sampler-rate-limited

Conversation

@lucaspimentel

@lucaspimentel lucaspimentel commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

Problem

  • Error trace rescue can retain every eligible sampled-out error trace when enabled, without a volume budget.
  • When the backend owns stats, the extension skips rescue, forwarding sampled-out error traces without the _dd.errors_sr marker needed to exempt them from backend P0 dropping.

Cause

  • The sampler uses AlwaysKeep mode behind an opt-in boolean.
  • Rescue shares the stats-dependent chunk-filtering gate, although rescue and stats ownership are independent.

This PR

  • Replace keep-all rescue ([APMSVLS-469] feat(traces): add error sampler to keep/rescue traces with errors #1320) with the shared Go/SCL rate-limited sampler. DD_APM_ERROR_TPS (YAML: apm_error_tps) defaults to 10 errored traces/s per execution environment, shared across signatures and invocations. Values <= 0 disable rescue.
  • Run rescue for every stats owner: tracer, extension, or backend. Stamp rescued roots with _dd.errors_sr without changing sampling priority. Preserve existing chunk forwarding/filtering, eligibility rules, and the pre-rescue stats snapshot; remove the obsolete stats-dependent startup warning.
  • Deprecate DD_SERVERLESS_ERROR_SAMPLER_ENABLED and warn whenever it is set. A valid TPS setting takes precedence; otherwise legacy false disables rescue and legacy true or an unset flag uses the default budget.
  • Resolve configuration as valid env TPS > valid YAML TPS > legacy flag > default. Warn about and ignore invalid values per source.
  • Migration: rescue is now enabled by default regardless of stats ownership, and previously enabled keep-all rescue becomes rate-limited. Set DD_APM_ERROR_TPS=0 to disable it.
  • Caveats: the budget is approximate, not a hard ceiling. Freeze/thaw expires stale counters but preserves throttled rates, which recover by at most 20% per bucket recomputation and can also throttle unseen signatures.

Testing

Test 1: Configuration and rescue regressions

Steps

  • Run config and sampler tests covering precedence, invalid values, legacy compatibility, disabled/shared budgets, clock jumps, freeze/thaw, and existing space-separated DD_APM_FEATURES support.
  • Exercise unit and pipeline rescue tests across all stats-owner combinations, plus a real-binary backend-owned-stats regression against the fake Lambda API and intake.

Result

  • Focused tests pass. Regressions verified failing before the fix now pass, checking rescue markers, unchanged priority, preserved forwarding, and untouched stats snapshots.

Test 2: Formatting, lint, and workspace validation

Steps

  • Run cargo fmt --all -- --check, workspace clippy with default and default,test-mode, and cargo nextest run --workspace --no-fail-fast.

Result

  • Formatting and clippy pass. Workspace validation is environment-limited: sandbox TLS tests fail localhost DNS resolution but pass on the host; host process tests are blocked by occupied ports 8125/8126. The process tests, including the new regression, pass in the sandbox.

@datadog-prod-us1-3

datadog-prod-us1-3 Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Pipelines

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: e669ebe | Docs | Give us feedback!

@lucaspimentel lucaspimentel changed the title feat(bottlecap): rate-limit error trace rescue with DD_APM_ERROR_TPS [APMSVLS-469] feat(bottlecap): rate-limit error trace rescue with DD_APM_ERROR_TPS Nov 3, 2026
@lucaspimentel
lucaspimentel marked this pull request as ready for review November 3, 2026 21:33
@lucaspimentel
lucaspimentel requested review from a team as code owners November 3, 2026 21:33
@lucaspimentel
lucaspimentel requested review from clifordshelton and a balanced review from Copilot November 3, 2026 21:33
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-07T06:49:46.336781Z e669ebe New commits
🔒 Security Review ✅ Completed 2026-11-07T06:50:35.825436Z e669ebe New commits
ℹ️ 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.

@lucaspimentel

Copy link
Copy Markdown
Member Author

@DataDog review

@lucaspimentel
lucaspimentel force-pushed the lpimentel/error-sampler-rate-limited branch from 31b98de to e6e7837 Compare November 3, 2026 21:34

@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: 31b98deb11

ℹ️ 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 PLAN-error-sampler-tps.md Resolved

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

Bits Code Review: PASS

More details

Configuration precedence, disabling rules, and startup wiring are consistent with the documented rescue-budget behavior. Runtime sampler behavior remains unverified.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit 31b98de

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.

🟡 Changes recommended

Concurrent batches crossing a 5-second boundary can reset live sampler counts and distort rescue rates, while the freeze/thaw regression test does not verify that rescue resumes after a gap.

2 open issues
What changed in this PR

This follow-up to #1320 replaces keep-all error trace rescue with a configurable, per-execution-environment rate limit while preserving the existing compute-stats gate.

Changes:

  • Adds DD_APM_ERROR_TPS with a default of 10 TPS, invalid-value fallback, and legacy-flag compatibility.
  • Switches rescue to RateLimited mode and updates startup warnings.
  • Expands configuration and sampler regression coverage, including shared budgets and freeze/thaw behavior.
File Description
PLAN-error-sampler-tps.md Records implementation plans, caveats, and follow-up scope.
bottlecap/​tests/​apm_integration_test.rs Uses the default TPS budget in integration fixtures.
bottlecap/​src/​traces/​trace_processor.rs Enables rate-limited sampling and adds regression tests.
bottlecap/​src/​traces/​trace_agent.rs Updates the disabled-sampler test fixture.
bottlecap/​src/​startup.rs Wires the resolved budget and configuration warnings.
bottlecap/​src/​lifecycle/​invocation/​processor.rs Updates tests to use the renamed sampler helper.
bottlecap/​src/​lifecycle/​invocation/​processor_service.rs Uses a zero budget to disable rescue in tests.
bottlecap/​src/​config/​mod.rs Adds TPS parsing, precedence, legacy warnings, and configuration tests.

Review effort: Balanced

Comment thread bottlecap/src/traces/trace_processor.rs Resolved
Comment thread bottlecap/src/traces/trace_processor.rs Resolved
@lucaspimentel lucaspimentel changed the title [APMSVLS-469] feat(bottlecap): rate-limit error trace rescue with DD_APM_ERROR_TPS [APMSVLS-469] Rate-limit error trace rescue with DD_APM_ERROR_TPS Nov 4, 2026
Comment thread bottlecap/src/config/mod.rs Resolved
@lucaspimentel
lucaspimentel force-pushed the lpimentel/error-sampler-rate-limited branch 2 times, most recently from d395f60 to ad85245 Compare November 6, 2026 02:16

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

ℹ️ 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/config/mod.rs Resolved
@lucaspimentel
lucaspimentel force-pushed the lpimentel/error-sampler-rate-limited branch 2 times, most recently from f1c205e to 296e853 Compare November 7, 2026 02:24
@DataDog DataDog deleted a comment from datadog-datadog-prod-us1 Bot Nov 7, 2026
@DataDog DataDog deleted a comment from chatgpt-codex-connector Bot Nov 7, 2026
@DataDog DataDog deleted a comment from chatgpt-codex-connector Bot Nov 7, 2026
Planning notes for rate-limited error trace rescue and the deprecation of DD_SERVERLESS_ERROR_SAMPLER_ENABLED. To be deleted before the PR merges.
Error trace rescue now uses a rate-limited budget instead of an on/off switch: it is on by default at 10 errored traces per second per execution environment when the extension computes stats.

Set DD_APM_ERROR_TPS<=0 to disable rescue, or a positive value to change the budget. Exponent values without a decimal point, such as 1e3, are rejected as invalid.

DD_SERVERLESS_ERROR_SAMPLER_ENABLED is deprecated and now logs a startup warning; DD_APM_ERROR_TPS wins when both are set.
@lucaspimentel
lucaspimentel force-pushed the lpimentel/error-sampler-rate-limited branch from 193b761 to bd26a88 Compare November 7, 2026 05:16

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

ℹ️ 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/startup.rs Resolved
lambda_extension_compute_stats does not affect the error sampler
resolution or the deprecation warning, so the duplicate table rows
asserted identical outcomes.

@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: 0fe5f63141

ℹ️ 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 Resolved
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