← Back to Pull requests

refactor(debugger): probe coordination #19466

Closed
unknown closed this pull request without merging on Oct 21, 2026 09:59 UTC
View on GitHub
unknown unknown commented on Aug 03, 2026 15:51 UTC
Author

Description

Every Dynamic Instrumentation snapshot probe used to make its own sampling decision, against its own rate limit and, for line probes only, a global rate limit. Related probes therefore sampled independently, and a chain of snapshots (a function probe plus the line probes inside it, a caller and its callees, a handler and the probes it reaches) routinely arrived with pieces missing, with nothing to tell the consumer that anything was absent.

This change replaces the per-probe decision with coordinated sampling, keyed on the trace:

  • One decision per trace. The first capture in a trace admits the trace, atomically, against the global rate limit. Every probe in the trace inherits that decision: an admitted trace captures from all of its probes, and a rejected trace captures from none. A rejected trace stays rejected even if budget becomes available later, so a chain is never admitted halfway through.

  • Charged at capture time. The budget is charged when values are about to be captured, after the probe condition has matched, which is the expensive part. Firings whose condition does not match cost nothing. Every capture in an admitted trace is charged, and the budget may go into deficit, so new traces are turned away until it is repaid.

  • One snapshot per probe per trace. Within a trace, each probe captures at most once, so a probe in a hot loop cannot crowd out the probes around it.

  • No trace, no coordination. A snapshot probe firing outside of any trace is admitted on its own against the global rate limit and is held to its own rate (one per second by default), as before.

  • Out of scope. Probes that take no snapshot, exception replay and code origin do not take part in coordination and are only held to their own rate limit. Probes of an active Live Debugger session are left to the session budget.
  • Implementation

  • ddtrace/debugging/_sampling.py (new) holds all of the sampling logic in DebuggerSampler, a global state manager in the style of Session. It is started by Debugger.enable() and stopped by Debugger.disable(); while stopped, no coordinated probe may fire.

  • Signals consult the sampler twice and get a Decision back: a cheap, lock-free gate before the condition is evaluated (so firings in a rejected trace, or of a probe that already captured, skip condition evaluation entirely), and atomic admission right before capture. Drops are recorded as the existing SKIP_* signal states, so the collector keeps reporting the guardrail metric reasons. The debugger itself no longer makes sampling decisions, and the global_limiter argument of Signal.do_line is gone.

  • Function probes are gated when they are evaluated: probes evaluated on exit are gated on exit, not on entry.

  • The coordination unit is abstracted as a SamplingContext, with TraceContext storing the decision and the captured probes on the local root span. Coordinating on another kind of unit of execution only needs a new subclass and a change to how the context is derived.

  • A root span can be active on several threads when the execution context is copied (e.g. asyncio.to_thread), so admission, the recorded decision and the per-probe cap are guarded by a lock taken only at capture time. Nothing that can call back into application code (such as logging) runs while it is held.

  • BudgetRateLimiterWithJitter gains has_budget() (a non-consuming peek) and consume() (a charge that may go into deficit). has_budget() compares before capping, so a maximum budget just under one token (e.g. a rate of 49/s) does not reject forever, and infinite rates no longer risk turning the budget into NaN when no time has elapsed.
  • Refs: DEBUG-5827

    Testing

  • tests/debugging/test_sampling.py (new) covers the sampler directly: per-trace decision and its persistence, atomic admission between concurrent traces, threads sharing one root span, races between a gate rejection and an admission, the per-probe cap (per trace, not per span; single shot, not a rate), budget deficit, the no-trace path, non-snapshot probes, sessions, the stopped sampler, logging outside the lock, and exception replay and code origin staying out of coordination.

  • tests/debugging/test_debugger.py adds end-to-end tests through the debugger: loop probes capped per trace, whole chains sharing one decision and dropping together, exit-timed probes gated on exit, inactive session probes not deciding for the trace, and the sampler lifecycle.

  • tests/tracer/test_rate_limiter.py covers has_budget(), consume(), maximum budgets below one token, and infinite rates with no elapsed time.
  • Risks

  • Behaviour change for snapshot probes inside traces: they are capped at one snapshot per trace rather than by their own per-second rate, so a probe on an endpoint that serves many traces per second can capture more often than before, up to the global rate limit. Outside of traces the probe rate still applies.

  • Function snapshot probes are now subject to the global rate limit, which previously only applied to line probes.

  • Within a rejected trace, or for a probe that already captured in it, the condition is not evaluated, so condition evaluation errors are not reported for those firings.

  • A long-lived local root span (e.g. one around the whole application) makes the whole process one coordination unit, so each probe captures at most once while it is open.
  • Additional Notes

  • Only trace-based coordination is implemented. Coordinating firings that happen outside of any trace on a runtime execution context is left for a follow-up; the SamplingContext abstraction is meant to make that a self-contained change.

  • Each exception replay snapshot now gets its own probe ID. Exception replay snapshots are correlated with the exception by exceptionId and the span tags, not by probe ID.
  • [DEBUG-5827]: https://datadoghq.atlassian.net/browse/DEBUG-5827?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: grantseltzer Review duration: 113408m
    All Vouch review confidence checks passed
    Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #19466"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 20.5% · Safe to merge
    20.5%