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 =
/\A[a-zA-Z][-.\w]{0,62}\z/
Instance Method Summary collapse
- #add_metric_reader(metric_reader) ⇒ Object private
- #create_instrument(kind, name, unit, description, callback) ⇒ Object
-
#initialize(name, version, meter_provider) ⇒ Meter
constructor
private
Returns a new Meter instance.
- #utf8mb3_encoding?(string) ⇒ Boolean
Constructor Details
#initialize(name, version, meter_provider) ⇒ 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.
24 25 26 27 28 29 |
# File 'lib/opentelemetry/sdk/metrics/meter.rb', line 24 def initialize(name, version, meter_provider) @mutex = Mutex.new @instrument_registry = {} @instrumentation_scope = InstrumentationScope.new(name, version) @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.
32 33 34 35 36 |
# File 'lib/opentelemetry/sdk/metrics/meter.rb', line 32 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) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/opentelemetry/sdk/metrics/meter.rb', line 38 def create_instrument(kind, name, unit, description, callback) raise InstrumentNameError if name.nil? raise InstrumentNameError if name.empty? raise InstrumentNameError unless NAME_REGEX.match?(name) raise InstrumentUnitError if unit && (!unit.ascii_only? || unit.size > 63) raise InstrumentDescriptionError if description && (description.size > 1023 || !utf8mb3_encoding?(description.dup)) super do case kind when :counter then OpenTelemetry::SDK::Metrics::Instrument::Counter.new(name, unit, description, @instrumentation_scope, @meter_provider) when :observable_counter then OpenTelemetry::SDK::Metrics::Instrument::ObservableCounter.new(name, unit, description, callback, @instrumentation_scope, @meter_provider) when :histogram then OpenTelemetry::SDK::Metrics::Instrument::Histogram.new(name, unit, description, @instrumentation_scope, @meter_provider) when :observable_gauge then OpenTelemetry::SDK::Metrics::Instrument::ObservableGauge.new(name, unit, description, callback, @instrumentation_scope, @meter_provider) when :up_down_counter then OpenTelemetry::SDK::Metrics::Instrument::UpDownCounter.new(name, unit, description, @instrumentation_scope, @meter_provider) when :observable_up_down_counter then OpenTelemetry::SDK::Metrics::Instrument::ObservableUpDownCounter.new(name, unit, description, callback, @instrumentation_scope, @meter_provider) end end end |
#utf8mb3_encoding?(string) ⇒ Boolean
57 58 59 60 |
# File 'lib/opentelemetry/sdk/metrics/meter.rb', line 57 def utf8mb3_encoding?(string) string.force_encoding('UTF-8').valid_encoding? && string.each_char { |c| return false if c.bytesize >= 4 } end |