Class: Datadog::DI::CorrelationSampler Private
- Inherits:
-
Object
- Object
- Datadog::DI::CorrelationSampler
- Defined in:
- lib/datadog/di/correlation_sampler.rb,
lib/datadog/di/correlation_sampler/trace_budget.rb,
lib/datadog/di/correlation_sampler/trace_budget_ledger.rb,
lib/datadog/di/correlation_sampler/trace_budget_ledger/entry.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Sampling gate that coordinates capturing Live Debugger probe hits within one trace and bounds total snapshot volume with process-wide budgets.
Defined Under Namespace
Classes: TraceBudget, TraceBudgetLedger
Constant Summary collapse
- DEFAULT_SWEEP_THRESHOLD =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Sweep floor for the per-trace budget ledger.
4096- TOP_RATE =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Snapshots per second, process-wide, that may establish an emitting trace.
10- GLOBAL_RATE =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Snapshots per second, process-wide, across all emits.
20- PER_PROBE_BUDGET =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Snapshots one probe may emit within one trace.
1- ALL_BUDGET =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Snapshots all probes together may emit within one trace.
20
Instance Method Summary collapse
-
#admit_process_wide_snapshot? ⇒ Boolean
private
Consumes one GLOBAL token for a snapshot payload the coordinated emit path does not gate, such as a condition-evaluation-failure notification with no active trace or from a non-capturing probe.
-
#after_fork! ⇒ void
private
Rebuilds the process-scoped state for a freshly forked child.
-
#emit?(probe, trace) ⇒ Boolean
private
Decides whether this capturing probe hit emits a snapshot.
-
#emit_with_reason?(probe, trace) ⇒ Array(Boolean, Symbol, nil)
private
Decides whether this capturing probe hit emits a snapshot, and names the drop decision for a denial.
-
#initialize(sweep_threshold: DEFAULT_SWEEP_THRESHOLD, top_rate: TOP_RATE, global_rate: GLOBAL_RATE, per_probe_budget: PER_PROBE_BUDGET, all_budget: ALL_BUDGET) ⇒ void
constructor
private
Initializes an empty per-trace ledger and full process-wide TOP/GLOBAL buckets.
Constructor Details
#initialize(sweep_threshold: DEFAULT_SWEEP_THRESHOLD, top_rate: TOP_RATE, global_rate: GLOBAL_RATE, per_probe_budget: PER_PROBE_BUDGET, all_budget: ALL_BUDGET) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Initializes an empty per-trace ledger and full process-wide TOP/GLOBAL buckets.
45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/datadog/di/correlation_sampler.rb', line 45 def initialize(sweep_threshold: DEFAULT_SWEEP_THRESHOLD, top_rate: TOP_RATE, global_rate: GLOBAL_RATE, per_probe_budget: PER_PROBE_BUDGET, all_budget: ALL_BUDGET) TraceBudget.validate_budgets!(per_probe_budget: per_probe_budget, all_budget: all_budget) @per_probe_budget = per_probe_budget @all_budget = all_budget @sweep_threshold = sweep_threshold @top_rate = top_rate @global_rate = global_rate rebuild_state end |
Instance Method Details
#admit_process_wide_snapshot? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Consumes one GLOBAL token for a snapshot payload the coordinated emit path does not gate, such as a condition-evaluation-failure notification with no active trace or from a non-capturing probe. GLOBAL admits the payload only while the balance is positive, matching the uncorrelated emit path, so condition-error payloads and capturing emits share one process-wide snapshot budget.
97 98 99 100 101 |
# File 'lib/datadog/di/correlation_sampler.rb', line 97 def admit_process_wide_snapshot? lock.synchronize do global_limiter.try_consume end end |
#after_fork! ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Rebuilds the process-scoped state for a freshly forked child. Must run while the child is single-threaded.
107 108 109 110 |
# File 'lib/datadog/di/correlation_sampler.rb', line 107 def after_fork! rebuild_state nil end |
#emit?(probe, trace) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Decides whether this capturing probe hit emits a snapshot.
84 85 86 87 |
# File 'lib/datadog/di/correlation_sampler.rb', line 84 def emit?(probe, trace) admitted, = emit_with_reason?(probe, trace) admitted end |
#emit_with_reason?(probe, trace) ⇒ Array(Boolean, Symbol, nil)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Decides whether this capturing probe hit emits a snapshot, and names the drop decision for a denial.
66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/datadog/di/correlation_sampler.rb', line 66 def emit_with_reason?(probe, trace) lock.synchronize do return (probe) if trace.nil? budget = trace_budgets.fetch(trace) if budget (budget, probe) else emit_first_probe?(probe, trace) end end end |