Class: OpenTelemetry::SDK::Metrics::Aggregation::LastValue
- Inherits:
-
Object
- Object
- OpenTelemetry::SDK::Metrics::Aggregation::LastValue
- Includes:
- StreamScopedStorage
- 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
Returns the current data points, clearing them for delta temporality.
-
#initialize(exemplar_reservoir: nil) ⇒ LastValue
constructor
A new instance of LastValue.
-
#update(increment, attributes, data_points, cardinality_limit, exemplar_offer: false) ⇒ Object
Replaces the last recorded value for the given attributes.
Constructor Details
#initialize(exemplar_reservoir: nil) ⇒ LastValue
Returns a new instance of LastValue.
22 23 24 25 |
# File 'lib/opentelemetry/sdk/metrics/aggregation/last_value.rb', line 22 def initialize(exemplar_reservoir: nil) @exemplar_reservoir = exemplar_reservoir || DEFAULT_RESERVOIR @exemplar_reservoir_storage = new_stream_storage end |
Instance Attribute Details
#exemplar_reservoir ⇒ Object (readonly)
Returns the value of attribute exemplar_reservoir.
16 17 18 |
# File 'lib/opentelemetry/sdk/metrics/aggregation/last_value.rb', line 16 def exemplar_reservoir @exemplar_reservoir end |
Instance Method Details
#collect(start_time, end_time, data_points) ⇒ Object
Returns the current data points, clearing them for delta temporality.
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/opentelemetry/sdk/metrics/aggregation/last_value.rb', line 28 def collect(start_time, end_time, data_points) stream_exemplar_reservoir_storage = @exemplar_reservoir_storage[data_points] ndps = data_points.values.map! do |ndp| ndp.start_time_unix_nano = start_time ndp.time_unix_nano = end_time reservoir = stream_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
Replaces the last recorded value for the given attributes.
43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/opentelemetry/sdk/metrics/aggregation/last_value.rb', line 43 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, data_points, exemplar_offer: exemplar_offer) nil end |