lib/opentelemetry/sdk/metrics/meter_provider.rb in opentelemetry-metrics-sdk-0.2.0 vs lib/opentelemetry/sdk/metrics/meter_provider.rb in opentelemetry-metrics-sdk-0.3.0
- old
+ new
@@ -12,18 +12,19 @@
# {MeterProvider} is the SDK implementation of {OpenTelemetry::Metrics::MeterProvider}.
class MeterProvider < OpenTelemetry::Metrics::MeterProvider
Key = Struct.new(:name, :version)
private_constant(:Key)
- attr_reader :resource, :metric_readers
+ attr_reader :resource, :metric_readers, :registered_views
def initialize(resource: OpenTelemetry::SDK::Resources::Resource.create)
@mutex = Mutex.new
@meter_registry = {}
@stopped = false
@metric_readers = []
@resource = resource
+ @registered_views = []
end
# Returns a {Meter} instance.
#
# @param [String] name Instrumentation package name
@@ -34,10 +35,11 @@
version ||= ''
if @stopped
OpenTelemetry.logger.warn 'calling MeterProvider#meter after shutdown, a noop meter will be returned.'
OpenTelemetry::Metrics::Meter.new
else
+ OpenTelemetry.logger.warn "Invalid meter name provided: #{name.nil? ? 'nil' : 'empty'} value" if name.to_s.empty?
@mutex.synchronize { @meter_registry[Key.new(name, version)] ||= Meter.new(name, version, self) }
end
end
# Attempts to stop all the activity for this {MeterProvider}.
@@ -123,16 +125,33 @@
instrument.register_with_new_metric_store(mr.metric_store)
end
end
end
- # 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).
- def add_view
- # TODO: For each meter add this view to all applicable instruments
+ # A View provides SDK users with the flexibility to customize the metrics that are output by the SDK.
+ #
+ # Example:
+ #
+ # OpenTelemetry.meter_provider.add_view('test', :aggregation => Aggregation::Drop.new,
+ # :type => :counter, :unit => 'smidgen',
+ # :meter_name => 'test', :meter_version => '1.0')
+ #
+ #
+ # @param [String] name Name of the view.
+ # @param [optional Hash] options For more precise matching, {View} and {MetricsStream}
+ # options may include:
+ # aggregation: An instance of an aggregation class, e.g. {ExplicitBucketHistogram}, {Sum}, {LastValue}
+ # type: A Symbol representing the instrument kind, e.g. :observable_gauge, :counter
+ # unit: A String matching an instrumentation unit, e.g. 'smidgen'
+ # meter_name: A String matching a meter name, e.g. meter_provider.meter('sample_meter_name', version: '1.2.0'), would be 'sample_meter_name'
+ # meter_version: A String matching a meter version, e.g. meter_provider.meter('sample_meter_name', version: '1.2.0'), would be '1.2.0'
+ #
+ # @return [nil] returns nil
+ #
+ def add_view(name, **options)
+ # TODO: add schema_url as part of options
+ @registered_views << View::RegisteredView.new(name, **options)
+ nil
end
end
end
end
end