Skip to content

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

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

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

Conversation

@lucaspimentel

@lucaspimentel lucaspimentel commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

Overview

Replace keep-all error trace rescue (#1320) with the shared Go/SCL rate-limited sampler.

  • Budget: DD_APM_ERROR_TPS (YAML: apm_error_tps) defaults to 10 errored traces/s per execution environment, shared across invocations. Values <= 0 disable rescue.
  • Gating unchanged: rescue requires DD_LAMBDA_EXTENSION_COMPUTE_STATS=true. An explicit TPS setting without it logs a startup warning.
  • Legacy flag: deprecate DD_SERVERLESS_ERROR_SAMPLER_ENABLED and warn whenever it is set. false disables rescue only when no valid TPS is configured; valid TPS always wins.
  • Configuration: env overrides YAML. Invalid values are warned about and ignored per source, falling back to valid YAML, the legacy flag, then the default. Use 1.0e3, not 1e3, for exponent notation.
  • Behavior change: rescue is now enabled by default on the compute-stats path; previously enabled rescue becomes rate-limited, with _dd.errors_sr potentially below 1.0.
  • Caveats: the budget is approximate, not a hard ceiling. Freeze/thaw clears stale counters but preserves throttled rates, which recover by at most 20% per bucket recomputation and can also throttle unseen signatures.

Testing

  • Cover config precedence, invalid values, legacy compatibility, disabled budgets, shared budgets, clock jumps, and freeze/thaw behavior.
  • Regression-test existing space-separated DD_APM_FEATURES support.
  • Local validation passed: formatting, workspace and test-mode tests, and clippy with -D warnings for default, default+test-mode, and FIPS.

@datadog-prod-us1-3

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

Copy link
Copy Markdown

Pipelines

✨ Unblock PR with BitsAI

❌ Errors

Your PR has failed checks. Please review the issues below and take necessary action before merging.

🚦 2 Pipeline jobs failed

DDCI - DataDog/datadog-lambda-extension | e2e-test-status (amd64) — 🔧 Needs a code fix, caused by this PR

View more details · View in DDCI

DataDog/datadog-lambda-extension | e2e-test-status (amd64) — 🔧 Needs a code fix, caused by this PR

View more details · View in GitLab

Useful? React with 👍 / 👎

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: f1c205e | Docs | View more details | 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-06T20:55:17.077532Z f1c205e New commits
🔒 Security Review ✅ Completed 2026-11-06T20:56:37.214011Z f1c205e 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 on lines +416 to +417
(None, Some(true)) => Some(format!(
"DD_SERVERLESS_ERROR_SAMPLER_ENABLED (serverless_error_sampler_enabled) is deprecated and has no effect: error trace rescue is on by default at {DEFAULT_APM_ERROR_TPS} traces per second; use DD_APM_ERROR_TPS (apm_error_tps) to change the budget"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Qualify the legacy warning when stats are off

When DD_SERVERLESS_ERROR_SAMPLER_ENABLED=true is set while DD_LAMBDA_EXTENSION_COMPUTE_STATS remains false, this warning says error rescue is on by default at 10 TPS, but process_traces still invokes drop_sampled_out_chunks only when extension-side stats are enabled. The separate no-effect warning in startup.rs only checks apm_error_tps.is_some(), so legacy-only users receive no correction and may believe their errors are being rescued when they are not; make this warning conditional on the compute-stats gate or emit the same no-effect warning for the legacy setting.

Useful? React with 👍 / 👎.

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.

@codex is that fixed in PR #1358?

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: Didn't find any major issues. Bravo.

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".

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 Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: ad85245249

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

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.
The post-gap check only asserted on a Keep, so it also passed when rescue
returned Drop and would not notice rescue stopping after a long
freeze/thaw gap. Scan 400 distinct trace IDs at one post-gap timestamp,
require at least one Keep, and assert its errors_sr stays below 1.0 at
the capped recovery rate.
@lucaspimentel
lucaspimentel force-pushed the lpimentel/error-sampler-rate-limited branch from ad85245 to f1c205e Compare November 6, 2026 20:52
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