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
Instance Method Summary collapse
- #aggregation_temporality ⇒ Object
- #collect(start_time, end_time, data_points) ⇒ Object
-
#initialize(aggregation_temporality: :delta) ⇒ LastValue
constructor
A new instance of LastValue.
- #update(increment, attributes, data_points) ⇒ Object
Constructor Details
#initialize(aggregation_temporality: :delta) ⇒ LastValue
Returns a new instance of LastValue.
13 14 15 |
# File 'lib/opentelemetry/sdk/metrics/aggregation/last_value.rb', line 13 def initialize(aggregation_temporality: :delta) @aggregation_temporality = aggregation_temporality == :cumulative ? AggregationTemporality.cumulative : AggregationTemporality.delta end |
Instance Method Details
#aggregation_temporality ⇒ Object
48 49 50 |
# File 'lib/opentelemetry/sdk/metrics/aggregation/last_value.rb', line 48 def aggregation_temporality @aggregation_temporality.temporality end |
#collect(start_time, end_time, data_points) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/opentelemetry/sdk/metrics/aggregation/last_value.rb', line 17 def collect(start_time, end_time, data_points) if @aggregation_temporality.delta? # Set timestamps and 'move' data point values to result. ndps = data_points.values.map! do |ndp| ndp.start_time_unix_nano = start_time ndp.time_unix_nano = end_time ndp end data_points.clear ndps else # Update timestamps and take a snapshot. data_points.values.map! do |ndp| ndp.start_time_unix_nano ||= start_time # Start time of a data point is from the first observation. ndp.time_unix_nano = end_time ndp.dup end end end |
#update(increment, attributes, data_points) ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/opentelemetry/sdk/metrics/aggregation/last_value.rb', line 37 def update(increment, attributes, data_points) data_points[attributes] = NumberDataPoint.new( attributes, nil, nil, increment, nil ) nil end |