Class: OpenTelemetry::SDK::Trace::Samplers::ParentConsistentProbabilityBased Private

Inherits:
Object
  • Object
show all
Includes:
ConsistentProbabilityTraceState
Defined in:
lib/opentelemetry/sdk/trace/samplers/parent_consistent_probability_based.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.

The ParentConsistentProbabilityBased sampler is meant as an optional replacement for the ParentBased sampler. It is required to first validate the tracestate and then respect the sampled flag in the W3C traceparent.

The ParentConsistentProbabilityBased Sampler constructor takes a single Sampler argument, which is the Sampler to use in case the ParentConsistentProbabilityBased Sampler is called for a root span.

Instance Method Summary collapse

Constructor Details

#initialize(root) ⇒ ParentConsistentProbabilityBased

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 a new instance of ParentConsistentProbabilityBased.



23
24
25
# File 'lib/opentelemetry/sdk/trace/samplers/parent_consistent_probability_based.rb', line 23

def initialize(root)
  @root = root
end

Instance Method Details

#==(other) ⇒ 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.



27
28
29
# File 'lib/opentelemetry/sdk/trace/samplers/parent_consistent_probability_based.rb', line 27

def ==(other)
  @root == other.root
end

#descriptionObject

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.

See OpenTelemetry::SDK::Trace::Samplers.



34
35
36
# File 'lib/opentelemetry/sdk/trace/samplers/parent_consistent_probability_based.rb', line 34

def description
  "ParentConsistentProbabilityBased{root=#{@root.description}}"
end

#should_sample?(trace_id:, parent_context:, links:, name:, kind:, attributes:) ⇒ 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.

See OpenTelemetry::SDK::Trace::Samplers.

Returns:

  • (Boolean)


41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/opentelemetry/sdk/trace/samplers/parent_consistent_probability_based.rb', line 41

def should_sample?(trace_id:, parent_context:, links:, name:, kind:, attributes:)
  parent_span_context = OpenTelemetry::Trace.current_span(parent_context).context
  if !parent_span_context.valid?
    @root.should_sample?(trace_id: trace_id, parent_context: parent_context, links: links, name: name, kind: kind, attributes: attributes)
  else
    tracestate = sanitized_tracestate(trace_id, parent_span_context)
    if parent_span_context.trace_flags.sampled?
      Result.new(decision: Decision::RECORD_AND_SAMPLE, tracestate: tracestate)
    else
      Result.new(decision: Decision::DROP, tracestate: tracestate)
    end
  end
end