Class: OpenTelemetry::SDK::Trace::Samplers::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/opentelemetry/sdk/trace/samplers/result.rb

Overview

The Result class represents an arbitrary sampling result. It has boolean values for the sampling decision and whether to record events, and a collection of attributes to be attached to a sampled root span.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(decision:, attributes: nil) ⇒ Result

Returns a new sampling result with the specified decision and attributes.

Parameters:

  • decision (Symbol)

    Whether or not a span should be sampled and/or record events.

  • attributes (optional Hash<String, Object>) (defaults to: nil)

    A frozen or freezable hash containing attributes to be attached to the span.



32
33
34
35
# File 'lib/opentelemetry/sdk/trace/samplers/result.rb', line 32

def initialize(decision:, attributes: nil)
  @decision = decision
  @attributes = attributes.freeze || EMPTY_HASH
end

Instance Attribute Details

#attributesHash<String, Object> (readonly)

Returns a frozen hash of attributes to be attached span.

Returns:

  • (Hash<String, Object>)


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

def attributes
  @attributes
end

Instance Method Details

#recording?Boolean

Returns true if this span should record events, attributes, status, etc.

Returns:

  • (Boolean)

    recording decision



47
48
49
# File 'lib/opentelemetry/sdk/trace/samplers/result.rb', line 47

def recording?
  @decision != Decision::NOT_RECORD
end

#sampled?Boolean

Returns true if this span should be sampled.

Returns:

  • (Boolean)

    sampling decision



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

def sampled?
  @decision == Decision::RECORD_AND_SAMPLED
end