Class: OpenTelemetry::SDK::Metrics::Meter
- Inherits:
-
Metrics::Meter
- Object
- Metrics::Meter
- OpenTelemetry::SDK::Metrics::Meter
- Defined in:
- lib/opentelemetry/sdk/metrics/meter.rb
Overview
Meter is the SDK implementation of Metrics::Meter.
Constant Summary collapse
- NAME_REGEX =
%r{\A[a-zA-Z][-./\w]{0,254}\z}
Instance Method Summary collapse
- #add_metric_reader(metric_reader) ⇒ Object private
-
#create_instrument(kind, name, unit, description, callback, exemplar_filter, exemplar_reservoir, advisory) ⇒ Object
Validates the given instrument options and creates the instrument of the given kind.
-
#initialize(name, version, meter_provider, attributes: nil) ⇒ Meter
constructor
private
Returns a new Meter instance.
-
#register_callback(instruments, callback) ⇒ Object
Multiple-instrument callbacks Callbacks registered after the time of instrument creation MAY be associated with multiple instruments.
-
#unregister(instruments, callback) ⇒ Object
Removes callback from the given instruments.
Constructor Details
#initialize(name, version, meter_provider, attributes: nil) ⇒ Meter
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 OpenTelemetry::SDK::Metrics::Meter instance.
26 27 28 29 30 31 |
# File 'lib/opentelemetry/sdk/metrics/meter.rb', line 26 def initialize(name, version, meter_provider, attributes: nil) @mutex = Mutex.new @instrument_registry = {} @instrumentation_scope = InstrumentationScope.new(name, version, attributes || {}.freeze) @meter_provider = meter_provider end |
Instance Method Details
#add_metric_reader(metric_reader) ⇒ 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.
59 60 61 62 63 |
# File 'lib/opentelemetry/sdk/metrics/meter.rb', line 59 def add_metric_reader(metric_reader) @instrument_registry.each_value do |instrument| instrument.register_with_new_metric_store(metric_reader.metric_store) end end |
#create_instrument(kind, name, unit, description, callback, exemplar_filter, exemplar_reservoir, advisory) ⇒ Object
Validates the given instrument options and creates the instrument of the given kind. TODO: advisory parameters are accepted but not yet applied to stream configuration.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/opentelemetry/sdk/metrics/meter.rb', line 67 def create_instrument(kind, name, unit, description, callback, exemplar_filter, exemplar_reservoir, advisory) raise InstrumentNameError if name.nil? raise InstrumentNameError if name.empty? raise InstrumentNameError unless NAME_REGEX.match?(name) unit ||= '' description ||= '' super do case kind when :counter then OpenTelemetry::SDK::Metrics::Instrument::Counter.new(name, unit, description, @instrumentation_scope, @meter_provider, exemplar_filter, exemplar_reservoir) when :observable_counter then OpenTelemetry::SDK::Metrics::Instrument::ObservableCounter.new(name, unit, description, callback, @instrumentation_scope, @meter_provider, exemplar_filter, exemplar_reservoir) when :gauge then OpenTelemetry::SDK::Metrics::Instrument::Gauge.new(name, unit, description, @instrumentation_scope, @meter_provider, exemplar_filter, exemplar_reservoir) when :histogram then OpenTelemetry::SDK::Metrics::Instrument::Histogram.new(name, unit, description, @instrumentation_scope, @meter_provider, exemplar_filter, exemplar_reservoir) when :observable_gauge then OpenTelemetry::SDK::Metrics::Instrument::ObservableGauge.new(name, unit, description, callback, @instrumentation_scope, @meter_provider, exemplar_filter, exemplar_reservoir) when :up_down_counter then OpenTelemetry::SDK::Metrics::Instrument::UpDownCounter.new(name, unit, description, @instrumentation_scope, @meter_provider, exemplar_filter, exemplar_reservoir) when :observable_up_down_counter then OpenTelemetry::SDK::Metrics::Instrument::ObservableUpDownCounter.new(name, unit, description, callback, @instrumentation_scope, @meter_provider, exemplar_filter, exemplar_reservoir) end end end |
#register_callback(instruments, callback) ⇒ Object
Multiple-instrument callbacks Callbacks registered after the time of instrument creation MAY be associated with multiple instruments. Related spec: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/api.md#multiple-instrument-callbacks Related spec: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/api.md#synchronous-instrument-api
It is RECOMMENDED that the API authors use one of the following forms for the callback function: The list (or tuple, etc.) returned by the callback function contains (Instrument, Measurement) pairs. the Observable Result parameter receives an additional (Instrument, Measurement) pairs Here it chose the second form
45 46 47 48 49 |
# File 'lib/opentelemetry/sdk/metrics/meter.rb', line 45 def register_callback(instruments, callback) instruments.each do |instrument| instrument.register_callback(callback) end end |
#unregister(instruments, callback) ⇒ Object
Removes callback from the given instruments.
52 53 54 55 56 |
# File 'lib/opentelemetry/sdk/metrics/meter.rb', line 52 def unregister(instruments, callback) instruments.each do |instrument| instrument.unregister(callback) end end |