Class: OpenTelemetry::Internal::ProxyMeterProvider Private

Inherits:
Metrics::MeterProvider show all
Defined in:
lib/opentelemetry/internal/proxy_meter_provider.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.

ProxyMeterProvider is an implementation of Metrics::MeterProvider. It is the default global Meter provider returned by OpenTelemetry.meter_provider. It delegates to a “real” MeterProvider after the global meter provider is registered. It returns ProxyMeter instances until the delegate is installed.

Instance Method Summary collapse

Constructor Details

#initializeProxyMeterProvider

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::Internal::ProxyMeterProvider instance.



22
23
24
25
26
# File 'lib/opentelemetry/internal/proxy_meter_provider.rb', line 22

def initialize
  @mutex = Mutex.new
  @registry = {}
  @delegate = nil
end

Instance Method Details

#delegate=(provider) ⇒ 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.

Set the delegate Meter provider. If this is called more than once, a warning will be logged and superfluous calls will be ignored.

Parameters:

  • provider (MeterProvider)

    The Meter provider to delegate to



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/opentelemetry/internal/proxy_meter_provider.rb', line 32

def delegate=(provider)
  unless @delegate.nil?
    OpenTelemetry.logger.warn 'Attempt to reset delegate in ProxyMeterProvider ignored.'
    return
  end

  @mutex.synchronize do
    @delegate = provider
    @registry.each { |key, meter| meter.delegate = provider.meter(key.name, version: key.version) }
  end
end

#meter(name = nil, version: 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 Meter instance.

Parameters:

  • name (optional String) (defaults to: nil)

    Instrumentation package name

  • version (optional String) (defaults to: nil)

    Instrumentation package version

Returns:

  • (Meter)


50
51
52
53
54
55
56
# File 'lib/opentelemetry/internal/proxy_meter_provider.rb', line 50

def meter(name = nil, version: nil)
  @mutex.synchronize do
    return @delegate.meter(name, version: version) unless @delegate.nil?

    @registry[Key.new(name, version)] ||= ProxyMeter.new
  end
end