Class: OpenTelemetry::Instrumentation::Registry

Inherits:
Object
  • Object
show all
Defined in:
lib/opentelemetry/instrumentation/registry.rb

Overview

The instrumentation Registry contains information about instrumentation available and facilitates discovery, installation and configuration. This functionality is primarily useful for SDK implementors.

Instance Method Summary collapse

Constructor Details

#initializeRegistry

Returns a new instance of Registry.



14
15
16
17
# File 'lib/opentelemetry/instrumentation/registry.rb', line 14

def initialize
  @lock = Mutex.new
  @instrumentation = []
end

Instance Method Details

#install(instrumentation_names, instrumentation_config_map = {}) ⇒ Object

Install the specified instrumentation with optionally specified configuration.

Parameters:

  • instrumentation_names (Array<String>)

    An array of instrumentation names to install

  • instrumentation_config_map (optional Hash<String, Hash>) (defaults to: {})

    A map of instrumentation_name to config. This argument is optional and config can be passed for as many or as few instrumentations as desired.



44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/opentelemetry/instrumentation/registry.rb', line 44

def install(instrumentation_names, instrumentation_config_map = {})
  @lock.synchronize do
    instrumentation_names.each do |instrumentation_name|
      instrumentation = find_instrumentation(instrumentation_name)
      if instrumentation.nil?
        OpenTelemetry.logger.warn "Could not install #{instrumentation_name} because it was not found"
      else
        install_instrumentation(instrumentation, instrumentation_config_map[instrumentation.name])
      end
    end
  end
end

#install_all(instrumentation_config_map = {}) ⇒ Object

Install all instrumentation available and installable in this process.

Parameters:

  • instrumentation_config_map (optional Hash<String, Hash>) (defaults to: {})

    A map of instrumentation_name to config. This argument is optional and config can be passed for as many or as few instrumentations as desired.



62
63
64
65
66
67
68
# File 'lib/opentelemetry/instrumentation/registry.rb', line 62

def install_all(instrumentation_config_map = {})
  @lock.synchronize do
    @instrumentation.map(&:instance).each do |instrumentation|
      install_instrumentation(instrumentation, instrumentation_config_map[instrumentation.name])
    end
  end
end

#lookup(instrumentation_name) ⇒ Instrumentation

Lookup an instrumentation definition by name. Returns nil if +instrumentation_name+ is not found.

Parameters:

  • instrumentation_name (String)

    A stringified class name for an instrumentation

Returns:



31
32
33
34
35
# File 'lib/opentelemetry/instrumentation/registry.rb', line 31

def lookup(instrumentation_name)
  @lock.synchronize do
    find_instrumentation(instrumentation_name)
  end
end

#register(instrumentation) ⇒ 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.



20
21
22
23
24
# File 'lib/opentelemetry/instrumentation/registry.rb', line 20

def register(instrumentation)
  @lock.synchronize do
    @instrumentation << instrumentation
  end
end