Class: OpenTelemetry::SDK::Metrics::Aggregation::LastValue
- Inherits:
-
Object
- Object
- OpenTelemetry::SDK::Metrics::Aggregation::LastValue
- Defined in:
- lib/opentelemetry/sdk/metrics/aggregation/last_value.rb
Overview
Contains the implementation of the LastValue aggregation
Constant Summary collapse
- OVERFLOW_ATTRIBUTE_SET =
{ 'otel.metric.overflow' => true }.freeze
Instance Attribute Summary collapse
-
#exemplar_reservoir ⇒ Object
readonly
Returns the value of attribute exemplar_reservoir.
Instance Method Summary collapse
- #collect(start_time, end_time, data_points) ⇒ Object
-
#initialize(exemplar_reservoir: nil) ⇒ LastValue
constructor
A new instance of LastValue.
- #update(increment, attributes, data_points, cardinality_limit, exemplar_offer: false) ⇒ Object
Constructor Details
#initialize(exemplar_reservoir: nil) ⇒ LastValue
Returns a new instance of LastValue.
20 21 22 23 |
# File 'lib/opentelemetry/sdk/metrics/aggregation/last_value.rb', line 20 def initialize(exemplar_reservoir: nil) @exemplar_reservoir = exemplar_reservoir || DEFAULT_RESERVOIR @exemplar_reservoir_storage = {} end |
Instance Attribute Details
#exemplar_reservoir ⇒ Object (readonly)
Returns the value of attribute exemplar_reservoir.
14 15 16 |
# File 'lib/opentelemetry/sdk/metrics/aggregation/last_value.rb', line 14 def exemplar_reservoir @exemplar_reservoir end |
Instance Method Details
#collect(start_time, end_time, data_points) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/opentelemetry/sdk/metrics/aggregation/last_value.rb', line 25 def collect(start_time, end_time, data_points) ndps = data_points.values.map! do |ndp| ndp.start_time_unix_nano = start_time ndp.time_unix_nano = end_time reservoir = @exemplar_reservoir_storage[ndp.attributes] ndp.exemplars = reservoir&.collect(attributes: ndp.attributes, aggregation_temporality: :delta) ndp end data_points.clear ndps end |
#update(increment, attributes, data_points, cardinality_limit, exemplar_offer: false) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/opentelemetry/sdk/metrics/aggregation/last_value.rb', line 37 def update(increment, attributes, data_points, cardinality_limit, exemplar_offer: false) # Check if we already have this attribute set ndp = if data_points.key?(attributes) data_points[attributes] elsif data_points.size >= cardinality_limit - 1 data_points[OVERFLOW_ATTRIBUTE_SET] || create_new_data_point(OVERFLOW_ATTRIBUTE_SET, data_points) else create_new_data_point(attributes, data_points) end update_number_data_point(ndp, increment, exemplar_offer: exemplar_offer) nil end |