refactor(debugger): probe coordination #19466
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
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
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
grantseltzer
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:
Implementation
ddtrace/debugging/_sampling.py(new) holds all of the sampling logic inDebuggerSampler, a global state manager in the style ofSession. It is started byDebugger.enable()and stopped byDebugger.disable(); while stopped, no coordinated probe may fire.Decisionback: 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 existingSKIP_*signal states, so the collector keeps reporting the guardrail metric reasons. The debugger itself no longer makes sampling decisions, and theglobal_limiterargument ofSignal.do_lineis gone.SamplingContext, withTraceContextstoring 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.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.BudgetRateLimiterWithJittergainshas_budget()(a non-consuming peek) andconsume()(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.pyadds 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.pycovershas_budget(),consume(), maximum budgets below one token, and infinite rates with no elapsed time.Risks
Additional Notes
SamplingContextabstraction is meant to make that a self-contained change.exceptionIdand the span tags, not by probe ID.[DEBUG-5827]: https://datadoghq.atlassian.net/browse/DEBUG-5827?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ