Class: OpenTelemetry::SDK::Metrics::Exemplar::AlignedHistogramBucketExemplarReservoir

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

Overview

AlignedHistogramBucketExemplarReservoir

This Exemplar reservoir stores at most one exemplar per histogram bucket. It uses reservoir sampling within each bucket to ensure uniform distribution of exemplars across the value range.

This is the recommended reservoir for Explicit Bucket Histogram aggregation.

Instance Method Summary collapse

Constructor Details

#initialize(boundaries: nil) ⇒ AlignedHistogramBucketExemplarReservoir

Returns a new instance of AlignedHistogramBucketExemplarReservoir.

Parameters:

  • boundaries (Array<Numeric>) (defaults to: nil)

    The bucket boundaries for the histogram



23
24
25
26
# File 'lib/opentelemetry/sdk/metrics/exemplar/aligned_histogram_bucket_exemplar_reservoir.rb', line 23

def initialize(boundaries: nil)
  @boundaries = boundaries || DEFAULT_BOUNDARIES
  reset
end

Instance Method Details

#collect(attributes: nil, aggregation_temporality: nil) ⇒ Array<Exemplar>

Collects accumulated exemplars and optionally resets state

Parameters:

  • attributes (Hash) (defaults to: nil)

    The attributes to filter from exemplar attributes

  • aggregation_temporality (Symbol) (defaults to: nil)

    :delta or :cumulative

Returns:

  • (Array<Exemplar>)

    The collected exemplars



45
46
47
48
49
50
51
52
53
# File 'lib/opentelemetry/sdk/metrics/exemplar/aligned_histogram_bucket_exemplar_reservoir.rb', line 45

def collect(attributes: nil, aggregation_temporality: nil)
  exemplars = []
  @exemplar_buckets.each do |bucket|
    exemplars << bucket.collect(point_attributes: attributes)
  end
  reset if aggregation_temporality == :delta
  exemplars.compact!
  exemplars
end

#offer(value: nil, timestamp: nil, attributes: nil, context: nil) ⇒ Object

Offers a measurement to the reservoir for potential sampling

Parameters:

  • value (Numeric) (defaults to: nil)

    The measurement value

  • timestamp (Integer) (defaults to: nil)

    The timestamp in nanoseconds

  • attributes (Hash) (defaults to: nil)

    The complete set of attributes

  • context (Context) (defaults to: nil)

    The OpenTelemetry context



34
35
36
37
38
# File 'lib/opentelemetry/sdk/metrics/exemplar/aligned_histogram_bucket_exemplar_reservoir.rb', line 34

def offer(value: nil, timestamp: nil, attributes: nil, context: nil)
  bucket_index = find_histogram_bucket(value)
  @exemplar_buckets[bucket_index].offer(value: value, time_unix_nano: timestamp, attributes: attributes, context: context)
  nil
end

#resetObject



55
56
57
# File 'lib/opentelemetry/sdk/metrics/exemplar/aligned_histogram_bucket_exemplar_reservoir.rb', line 55

def reset
  @exemplar_buckets = Array.new(@boundaries.size + 1) { ExemplarBucket.new }
end