Class: Datadog::DI::CorrelationSampler::TraceBudgetLedger Private
- Inherits:
-
Object
- Object
- Datadog::DI::CorrelationSampler::TraceBudgetLedger
- Defined in:
- 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.
Store of per-trace budgets, keyed by the trace object and bound to its lifetime: an entry dies with its trace, and a live trace keeps its entry. Dead entries are dropped by a lazy sweep once the entry count passes the sweep high-water mark.
A continued trace is a distinct trace object and establishes its own unit. Datadog::Tracing.continue_trace! builds a new TraceOperation for the same trace id, and the ledger keys that object as a separate trace with its own budget.
Defined Under Namespace
Classes: Entry
Instance Attribute Summary collapse
-
#entries ⇒ Hash[Integer, Entry]
readonly
private
Retained budget entries keyed by trace object id.
-
#sweep_threshold ⇒ Integer
readonly
private
Floor of the sweep high-water mark.
Instance Method Summary collapse
-
#fetch(trace) ⇒ TraceBudget?
private
Returns the budget stored for
trace, or nil when the trace has no stored budget. -
#initialize(sweep_threshold) ⇒ void
constructor
private
Initializes the ledger with
sweep_thresholdas the floor of the sweep high-water mark. -
#store(trace, budget) ⇒ void
private
Stores
budgetfortrace.
Constructor Details
#initialize(sweep_threshold) ⇒ 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 the ledger with sweep_threshold as the floor of the
sweep high-water mark.
29 30 31 32 33 34 35 36 37 |
# File 'lib/datadog/di/correlation_sampler/trace_budget_ledger.rb', line 29 def initialize(sweep_threshold) unless sweep_threshold.is_a?(Integer) && sweep_threshold.positive? raise ArgumentError, "sweep_threshold must be a positive Integer: #{sweep_threshold}" end @sweep_threshold = sweep_threshold @entries = {} @live_count = 0 end |
Instance Attribute Details
#entries ⇒ Hash[Integer, Entry] (readonly)
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.
Retained budget entries keyed by trace object id.
47 48 49 |
# File 'lib/datadog/di/correlation_sampler/trace_budget_ledger.rb', line 47 def entries @entries end |
#sweep_threshold ⇒ Integer (readonly)
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.
Floor of the sweep high-water mark.
42 43 44 |
# File 'lib/datadog/di/correlation_sampler/trace_budget_ledger.rb', line 42 def sweep_threshold @sweep_threshold end |
Instance Method Details
#fetch(trace) ⇒ TraceBudget?
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.
Returns the budget stored for trace, or nil when the trace has no
stored budget. A dead weak reference is discarded as a miss.
54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/datadog/di/correlation_sampler/trace_budget_ledger.rb', line 54 def fetch(trace) entry = entries[trace.object_id] return nil unless entry if entry.trace_ref.weakref_alive? && entry.trace_ref.__getobj__.equal?(trace) entry.budget else entries.delete(trace.object_id) nil end end |
#store(trace, 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.
This method returns an undefined value.
Stores budget for trace.
71 72 73 74 75 |
# File 'lib/datadog/di/correlation_sampler/trace_budget_ledger.rb', line 71 def store(trace, budget) sweep if entries.size >= sweep_bound entries[trace.object_id] = Entry.new(trace_ref: WeakRef.new(trace), budget: budget) nil end |