Class: OpenTelemetry::SDK::Metrics::Exemplar::ExemplarBucket

Inherits:
Object
  • Object
show all
Defined in:
lib/opentelemetry/sdk/metrics/exemplar/exemplar_bucket.rb

Overview

ExemplarBucket Stores a single exemplar measurement and manages its lifecycle

Instance Method Summary collapse

Constructor Details

#initializeExemplarBucket

Returns a new instance of ExemplarBucket.



14
15
16
# File 'lib/opentelemetry/sdk/metrics/exemplar/exemplar_bucket.rb', line 14

def initialize
  reset
end

Instance Method Details

#collect(point_attributes:) ⇒ Exemplar?

May return an Exemplar and resets the bucket for the next sampling period

Parameters:

  • point_attributes (Hash)

    Attributes already included in the metric data point

Returns:

  • (Exemplar, nil)

    The collected exemplar or nil if nothing was offered



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/opentelemetry/sdk/metrics/exemplar/exemplar_bucket.rb', line 43

def collect(point_attributes:)
  return nil unless @offered

  filtered_attributes = (@attributes.reject { |k, _v| point_attributes.key?(k) } if @attributes && point_attributes)

  exemplar = Exemplar.new(
    filtered_attributes,
    @value,
    @time_unix_nano,
    @span_id,
    @trace_id
  )

  reset
  exemplar
end

#offer(value:, time_unix_nano:, attributes:, context:) ⇒ Object

Offers a measurement to be sampled

Parameters:

  • value (Numeric)

    Measured value

  • time_unix_nano (Integer)

    Measurement observation time in nanoseconds

  • attributes (Hash)

    Measurement attributes

  • context (Context)

    Measurement context



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/opentelemetry/sdk/metrics/exemplar/exemplar_bucket.rb', line 24

def offer(value:, time_unix_nano:, attributes:, context:)
  @value = value
  @time_unix_nano = time_unix_nano
  @attributes = attributes

  span = ::OpenTelemetry::Trace.current_span(context)
  span_context = span.context
  if span_context.valid?
    @span_id = span_context.span_id
    @trace_id = span_context.trace_id
  end

  @offered = true
end