Class: OpenTelemetry::Internal::ProxyTracerProvider Private

Inherits:
Trace::TracerProvider show all
Defined in:
lib/opentelemetry/internal/proxy_tracer_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.

ProxyTracerProvider is an implementation of Trace::TracerProvider. It is the default global tracer provider returned by OpenTelemetry.tracer_provider. It delegates to a “real” TracerProvider after the global tracer provider is registered. It returns ProxyTracer instances until the delegate is installed.

Instance Method Summary collapse

Constructor Details

#initializeProxyTracerProvider

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::ProxyTracerProvider instance.



22
23
24
25
26
# File 'lib/opentelemetry/internal/proxy_tracer_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 tracer provider. If this is called more than once, a warning will be logged and superfluous calls will be ignored.

Parameters:

  • provider (TracerProvider)

    The tracer provider to delegate to



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

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

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

#tracer(name = nil, version = nil) ⇒ Tracer

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 Tracer instance.

Parameters:

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

    Instrumentation package name

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

    Instrumentation package version

Returns:

  • (Tracer)


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

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

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