Class: OpenTelemetry::SDK::Trace::Samplers::ParentBased Private

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

This is a composite sampler. ParentBased helps distinguished between the following cases: * No parent (root span). * Remote parent (SpanContext.remote? with trace_flags.sampled?) * Remote parent (SpanContext.remote? with !trace_flags.sampled?) * Local parent (!SpanContext.remote? with trace_flags.sampled?) * Local parent (!SpanContext.remote? with !trace_flags.sampled?)

Instance Method Summary collapse

Constructor Details

#initialize(root, remote_parent_sampled, remote_parent_not_sampled, local_parent_sampled, local_parent_not_sampled) ⇒ ParentBased

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 ParentBased.



21
22
23
24
25
26
27
# File 'lib/opentelemetry/sdk/trace/samplers/parent_based.rb', line 21

def initialize(root, remote_parent_sampled, remote_parent_not_sampled, local_parent_sampled, local_parent_not_sampled)
  @root = root
  @remote_parent_sampled = remote_parent_sampled
  @remote_parent_not_sampled = remote_parent_not_sampled
  @local_parent_sampled = local_parent_sampled
  @local_parent_not_sampled = local_parent_not_sampled
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.



29
30
31
32
33
34
35
# File 'lib/opentelemetry/sdk/trace/samplers/parent_based.rb', line 29

def ==(other)
  @root == other.root &&
    @remote_parent_sampled == other.remote_parent_sampled &&
    @remote_parent_not_sampled == other.remote_parent_not_sampled &&
    @local_parent_sampled == other.local_parent_sampled &&
    @local_parent_not_sampled == other.local_parent_not_sampled
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.



40
41
42
# File 'lib/opentelemetry/sdk/trace/samplers/parent_based.rb', line 40

def description
  "ParentBased{root=#{@root.description}, remote_parent_sampled=#{@remote_parent_sampled.description}, remote_parent_not_sampled=#{@remote_parent_not_sampled.description}, local_parent_sampled=#{@local_parent_sampled.description}, local_parent_not_sampled=#{@local_parent_not_sampled.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)


47
48
49
50
51
52
53
54
55
56
57
# File 'lib/opentelemetry/sdk/trace/samplers/parent_based.rb', line 47

def should_sample?(trace_id:, parent_context:, links:, name:, kind:, attributes:)
  parent_span_context = OpenTelemetry::Trace.current_span(parent_context).context
  delegate = if !parent_span_context.valid?
               @root
             elsif parent_span_context.remote?
               parent_span_context.trace_flags.sampled? ? @remote_parent_sampled : @remote_parent_not_sampled
             else
               parent_span_context.trace_flags.sampled? ? @local_parent_sampled : @local_parent_not_sampled
             end
  delegate.should_sample?(trace_id: trace_id, parent_context: parent_context, links: links, name: name, kind: kind, attributes: attributes)
end