Module: OpenTelemetry::SDK::Trace::Samplers::ConsistentProbabilityTraceState Private
- Included in:
- ConsistentProbabilityBased, ParentConsistentProbabilityBased
- Defined in:
- lib/opentelemetry/sdk/trace/samplers/consistent_probability_tracestate.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
The ConsistentProbabilityTraceState module implements Tracestate parsing, validation and manipulation for the consistent probability-based samplers.
Instance Method Summary collapse
- #decimal(str) ⇒ Object private
-
#invariant(p, r, sampled) ⇒ Object
private
rubocop:disable Naming/UncommunicativeMethodParamName.
-
#new_tracestate(p: nil, r: nil) ⇒ Object
private
rubocop:disable Naming/UncommunicativeMethodParamName.
-
#parse_ot_vendor_tag(tracestate) {|p, r, rest| ... } ⇒ Object
private
parse_ot_vendor_tag parses the 'ot' vendor tag of the tracestate.
-
#update_tracestate(tracestate, p, r, rest) ⇒ Object
private
rubocop:disable Naming/UncommunicativeMethodParamName.
Instance Method Details
#decimal(str) ⇒ Object
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.
75 76 77 |
# File 'lib/opentelemetry/sdk/trace/samplers/consistent_probability_tracestate.rb', line 75 def decimal(str) str.to_i if !str.nil? && DECIMAL.match?(str) end |
#invariant(p, r, sampled) ⇒ Object
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.
rubocop:disable Naming/UncommunicativeMethodParamName
71 72 73 |
# File 'lib/opentelemetry/sdk/trace/samplers/consistent_probability_tracestate.rb', line 71 def invariant(p, r, sampled) # rubocop:disable Naming/UncommunicativeMethodParamName ((p <= r) == sampled) || (sampled && (p == 63)) end |
#new_tracestate(p: nil, r: nil) ⇒ Object
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.
rubocop:disable Naming/UncommunicativeMethodParamName
59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/opentelemetry/sdk/trace/samplers/consistent_probability_tracestate.rb', line 59 def new_tracestate(p: nil, r: nil) # rubocop:disable Naming/UncommunicativeMethodParamName if p.nil? && r.nil? OpenTelemetry::Trace::Tracestate.DEFAULT elsif p.nil? OpenTelemetry::Trace::Tracestate.from_hash('ot' => "r:#{r}") elsif r.nil? OpenTelemetry::Trace::Tracestate.from_hash('ot' => "p:#{p}") else OpenTelemetry::Trace::Tracestate.from_hash('ot' => "p:#{p};r:#{r}") end end |
#parse_ot_vendor_tag(tracestate) {|p, r, rest| ... } ⇒ Object
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.
parse_ot_vendor_tag parses the 'ot' vendor tag of the tracestate. It yields the parsed probability fields and the remaining tracestate. It returns the result of the block.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/opentelemetry/sdk/trace/samplers/consistent_probability_tracestate.rb', line 23 def parse_ot_vendor_tag(tracestate) return yield(nil, nil, nil) if tracestate.empty? ot = tracestate.value('ot') return yield(nil, nil, nil) if ot.nil? || ot.length > MAX_LIST_LENGTH # TODO: warn that we're rejecting the tracestate p = r = nil rest = +'' ot.split(';').each do |field| k, v = field.split(':', 2) # TODO: "the used keys MUST be unique." - do we need to validate this? case k when 'p' then p = decimal(v) when 'r' then r = decimal(v) else rest << ';' unless rest.empty? rest << field end end rest = nil if rest.empty? yield(p, r, rest) end |
#update_tracestate(tracestate, p, r, rest) ⇒ Object
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.
rubocop:disable Naming/UncommunicativeMethodParamName
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/opentelemetry/sdk/trace/samplers/consistent_probability_tracestate.rb', line 46 def update_tracestate(tracestate, p, r, rest) # rubocop:disable Naming/UncommunicativeMethodParamName # This could be more efficient and allocate less, however it *should* only be used for root spans and sanitizing invalid tracestate # in the most common configuration of parent_consistent_probability_based(root: consistent_probability_based(p)). ps = "p:#{p}" unless p.nil? rs = "r:#{r}" unless r.nil? ot = [ps, rs, rest].compact.join(';') if ot.empty? tracestate.delete('ot') else tracestate.set_value('ot', ot) end end |