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:, tracestate:, 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 => String, Numeric, Boolean, Array<String, Numeric, Boolean>}) (defaults to: nil)

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

  • tracestate (Tracestate)

    A Tracestate that will be associated with the Span through the new SpanContext. If the sampler returns an empty Tracestate here, the Tracestate will be cleared, so samplers SHOULD normally return the passed-in Tracestate if they do not intend to change it.



43
44
45
46
47
# File 'lib/opentelemetry/sdk/trace/samplers/result.rb', line 43

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

Instance Attribute Details

#attributesHash{String => String, Numeric, Boolean, Array<String, Numeric, Boolean>} (readonly)

Returns a frozen hash of attributes to be attached to the span.

Returns:

  • (Hash{String => String, Numeric, Boolean, Array<String, Numeric, Boolean>})


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

def attributes
  @attributes
end

#tracestateTracestate (readonly)

Returns a Tracestate to be associated with the span.

Returns:

  • (Tracestate)


28
29
30
# File 'lib/opentelemetry/sdk/trace/samplers/result.rb', line 28

def tracestate
  @tracestate
end

Instance Method Details

#recording?Boolean

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

Returns:

  • (Boolean)

    recording decision



59
60
61
# File 'lib/opentelemetry/sdk/trace/samplers/result.rb', line 59

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

#sampled?Boolean

Returns true if this span should be sampled.

Returns:

  • (Boolean)

    sampling decision



52
53
54
# File 'lib/opentelemetry/sdk/trace/samplers/result.rb', line 52

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