Class: OpenTelemetry::SDK::Metrics::State::MetricStream Private

Inherits:
Object
  • Object
show all
Defined in:
lib/opentelemetry/sdk/metrics/state/metric_stream.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

The MetricStream class provides SDK internal functionality that is not a part of the public API.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, description, unit, instrument_kind, meter_provider, instrumentation_scope, aggregation) ⇒ MetricStream

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of MetricStream.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/opentelemetry/sdk/metrics/state/metric_stream.rb', line 18

def initialize(
  name,
  description,
  unit,
  instrument_kind,
  meter_provider,
  instrumentation_scope,
  aggregation
)
  @name = name
  @description = description
  @unit = unit
  @instrument_kind = instrument_kind
  @meter_provider = meter_provider
  @instrumentation_scope = instrumentation_scope
  @default_aggregation = aggregation
  @data_points = {}
  @registered_views = []

  find_registered_view
  @mutex = Mutex.new
end

Instance Attribute Details

#data_pointsObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



16
17
18
# File 'lib/opentelemetry/sdk/metrics/state/metric_stream.rb', line 16

def data_points
  @data_points
end

#descriptionObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



16
17
18
# File 'lib/opentelemetry/sdk/metrics/state/metric_stream.rb', line 16

def description
  @description
end

#instrument_kindObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



16
17
18
# File 'lib/opentelemetry/sdk/metrics/state/metric_stream.rb', line 16

def instrument_kind
  @instrument_kind
end

#instrumentation_scopeObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



16
17
18
# File 'lib/opentelemetry/sdk/metrics/state/metric_stream.rb', line 16

def instrumentation_scope
  @instrumentation_scope
end

#nameObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



16
17
18
# File 'lib/opentelemetry/sdk/metrics/state/metric_stream.rb', line 16

def name
  @name
end

#unitObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



16
17
18
# File 'lib/opentelemetry/sdk/metrics/state/metric_stream.rb', line 16

def unit
  @unit
end

Instance Method Details

#aggregate_metric_data(start_time, end_time, aggregation: nil) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/opentelemetry/sdk/metrics/state/metric_stream.rb', line 68

def aggregate_metric_data(start_time, end_time, aggregation: nil)
  aggregator = aggregation || @default_aggregation
  MetricData.new(
    @name,
    @description,
    @unit,
    @instrument_kind,
    @meter_provider.resource,
    @instrumentation_scope,
    aggregator.collect(start_time, end_time, @data_points),
    aggregator.aggregation_temporality,
    start_time,
    end_time
  )
end

#collect(start_time, end_time) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/opentelemetry/sdk/metrics/state/metric_stream.rb', line 41

def collect(start_time, end_time)
  @mutex.synchronize do
    metric_data = []
    if @registered_views.empty?
      metric_data << aggregate_metric_data(start_time, end_time)
    else
      @registered_views.each { |view| metric_data << aggregate_metric_data(start_time, end_time, aggregation: view.aggregation) }
    end

    metric_data
  end
end

#find_registered_viewObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



84
85
86
87
88
# File 'lib/opentelemetry/sdk/metrics/state/metric_stream.rb', line 84

def find_registered_view
  return if @meter_provider.nil?

  @meter_provider.registered_views.each { |view| @registered_views << view if view.match_instrument?(self) }
end

#to_sObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/opentelemetry/sdk/metrics/state/metric_stream.rb', line 90

def to_s
  instrument_info = String.new
  instrument_info << "name=#{@name}"
  instrument_info << " description=#{@description}" if @description
  instrument_info << " unit=#{@unit}" if @unit
  @data_points.map do |attributes, value|
    metric_stream_string = String.new
    metric_stream_string << instrument_info
    metric_stream_string << " attributes=#{attributes}" if attributes
    metric_stream_string << " #{value}"
    metric_stream_string
  end.join("\n")
end

#update(value, attributes) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/opentelemetry/sdk/metrics/state/metric_stream.rb', line 54

def update(value, attributes)
  if @registered_views.empty?
    @mutex.synchronize { @default_aggregation.update(value, attributes, @data_points) }
  else
    @registered_views.each do |view|
      @mutex.synchronize do
        attributes ||= {}
        attributes.merge!(view.attribute_keys)
        view.aggregation.update(value, attributes, @data_points) if view.valid_aggregation?
      end
    end
  end
end