Class: OpenTelemetry::SDK::Metrics::MeterProvider
- Inherits:
-
Metrics::MeterProvider
- Object
- Metrics::MeterProvider
- OpenTelemetry::SDK::Metrics::MeterProvider
- Defined in:
- lib/opentelemetry/sdk/metrics/meter_provider.rb
Overview
MeterProvider is the SDK implementation of Metrics::MeterProvider.
Instance Attribute Summary collapse
-
#metric_readers ⇒ Object
readonly
Returns the value of attribute metric_readers.
-
#resource ⇒ Object
readonly
Returns the value of attribute resource.
Instance Method Summary collapse
-
#add_metric_reader(metric_reader) ⇒ Object
Adds a new MetricReader to this MeterProvider.
-
#add_view ⇒ Object
The type of the Instrument(s) (optional).
-
#force_flush(timeout: nil) ⇒ Integer
This method provides a way for provider to notify the registered MetricReader instances, so they can do as much as they could to consume or send the metrics.
-
#initialize(resource: OpenTelemetry::SDK::Resources::Resource.create) ⇒ MeterProvider
constructor
A new instance of MeterProvider.
-
#meter(name, version: nil) ⇒ Meter
Returns a Meter instance.
- #register_synchronous_instrument(instrument) ⇒ Object private
-
#shutdown(timeout: nil) ⇒ Integer
Attempts to stop all the activity for this MeterProvider.
Constructor Details
#initialize(resource: OpenTelemetry::SDK::Resources::Resource.create) ⇒ MeterProvider
Returns a new instance of MeterProvider.
19 20 21 22 23 24 25 |
# File 'lib/opentelemetry/sdk/metrics/meter_provider.rb', line 19 def initialize(resource: OpenTelemetry::SDK::Resources::Resource.create) @mutex = Mutex.new @meter_registry = {} @stopped = false @metric_readers = [] @resource = resource end |
Instance Attribute Details
#metric_readers ⇒ Object (readonly)
Returns the value of attribute metric_readers.
17 18 19 |
# File 'lib/opentelemetry/sdk/metrics/meter_provider.rb', line 17 def metric_readers @metric_readers end |
#resource ⇒ Object (readonly)
Returns the value of attribute resource.
17 18 19 |
# File 'lib/opentelemetry/sdk/metrics/meter_provider.rb', line 17 def resource @resource end |
Instance Method Details
#add_metric_reader(metric_reader) ⇒ Object
Adds a new MetricReader to this OpenTelemetry::SDK::Metrics::MeterProvider.
106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/opentelemetry/sdk/metrics/meter_provider.rb', line 106 def add_metric_reader(metric_reader) @mutex.synchronize do if @stopped OpenTelemetry.logger.warn('calling MetricProvider#add_metric_reader after shutdown.') else @metric_readers.push(metric_reader) @meter_registry.each_value { |meter| meter.add_metric_reader(metric_reader) } end nil end end |
#add_view ⇒ Object
The type of the Instrument(s) (optional). The name of the Instrument(s). OpenTelemetry SDK authors MAY choose to support wildcard characters, with the question mark (?) matching exactly one character and the asterisk character (*) matching zero or more characters. The name of the Meter (optional). The version of the Meter (optional). The schema_url of the Meter (optional).
133 134 135 |
# File 'lib/opentelemetry/sdk/metrics/meter_provider.rb', line 133 def add_view # TODO: For each meter add this view to all applicable instruments end |
#force_flush(timeout: nil) ⇒ Integer
This method provides a way for provider to notify the registered MetricReader instances, so they can do as much as they could to consume or send the metrics. Note: unlike Push Metric Exporter which can send data on its own schedule, Pull Metric Exporter can only send the data when it is being asked by the scraper, so ForceFlush would not make much sense.
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/opentelemetry/sdk/metrics/meter_provider.rb', line 83 def force_flush(timeout: nil) @mutex.synchronize do if @stopped Export::SUCCESS else start_time = OpenTelemetry::Common::Utilities. results = @metric_readers.map do |metric_reader| remaining_timeout = OpenTelemetry::Common::Utilities.maybe_timeout(timeout, start_time) if remaining_timeout&.zero? Export::TIMEOUT else metric_reader.force_flush(timeout: remaining_timeout) end end results.max || Export::SUCCESS end end end |
#meter(name, version: nil) ⇒ Meter
Returns a OpenTelemetry::SDK::Metrics::Meter instance.
33 34 35 36 37 38 39 40 41 |
# File 'lib/opentelemetry/sdk/metrics/meter_provider.rb', line 33 def meter(name, version: nil) version ||= '' if @stopped OpenTelemetry.logger.warn 'calling MeterProvider#meter after shutdown, a noop meter will be returned.' OpenTelemetry::Metrics::Meter.new else @mutex.synchronize { @meter_registry[Key.new(name, version)] ||= Meter.new(name, version, self) } end end |
#register_synchronous_instrument(instrument) ⇒ 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.
120 121 122 123 124 125 126 |
# File 'lib/opentelemetry/sdk/metrics/meter_provider.rb', line 120 def register_synchronous_instrument(instrument) @mutex.synchronize do @metric_readers.each do |mr| instrument.register_with_new_metric_store(mr.metric_store) end end end |
#shutdown(timeout: nil) ⇒ Integer
Attempts to stop all the activity for this OpenTelemetry::SDK::Metrics::MeterProvider.
Calls MetricReader#shutdown for all registered MetricReaders.
After this is called all the newly created OpenTelemetry::SDK::Metrics::Meters will be no-op.
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/opentelemetry/sdk/metrics/meter_provider.rb', line 52 def shutdown(timeout: nil) @mutex.synchronize do if @stopped OpenTelemetry.logger.warn('calling MetricProvider#shutdown multiple times.') Export::FAILURE else start_time = OpenTelemetry::Common::Utilities. results = @metric_readers.map do |metric_reader| remaining_timeout = OpenTelemetry::Common::Utilities.maybe_timeout(timeout, start_time) if remaining_timeout&.zero? Export::TIMEOUT else metric_reader.shutdown(timeout: remaining_timeout) end end @stopped = true results.max || Export::SUCCESS end end end |