lib/opentelemetry/instrumentation/registry.rb in opentelemetry-api-0.4.0 vs lib/opentelemetry/instrumentation/registry.rb in opentelemetry-api-0.5.0

- old
+ new

@@ -5,82 +5,82 @@ # SPDX-License-Identifier: Apache-2.0 module OpenTelemetry module Instrumentation # The instrumentation Registry contains information about instrumentation - # adapters available and facilitates discovery, installation and + # available and facilitates discovery, installation and # configuration. This functionality is primarily useful for SDK # implementors. class Registry def initialize @lock = Mutex.new - @adapters = [] + @instrumentation = [] end # @api private - def register(adapter) + def register(instrumentation) @lock.synchronize do - @adapters << adapter + @instrumentation << instrumentation end end - # Lookup an adapter definition by name. Returns nil if +adapter_name+ + # Lookup an instrumentation definition by name. Returns nil if +instrumentation_name+ # is not found. # - # @param [String] adapter_name A stringified class name for an adapter - # @return [Adapter] - def lookup(adapter_name) + # @param [String] instrumentation_name A stringified class name for an instrumentation + # @return [Instrumentation] + def lookup(instrumentation_name) @lock.synchronize do - find_adapter(adapter_name) + find_instrumentation(instrumentation_name) end end - # Install the specified adapters with optionally specified configuration. + # Install the specified instrumentation with optionally specified configuration. # - # @param [Array<String>] adapter_names An array of adapter names to + # @param [Array<String>] instrumentation_names An array of instrumentation names to # install - # @param [optional Hash<String, Hash>] adapter_config_map A map of - # adapter_name to config. This argument is optional and config can be - # passed for as many or as few adapters as desired. - def install(adapter_names, adapter_config_map = {}) + # @param [optional Hash<String, Hash>] instrumentation_config_map 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. + def install(instrumentation_names, instrumentation_config_map = {}) @lock.synchronize do - adapter_names.each do |adapter_name| - adapter = find_adapter(adapter_name) - OpenTelemetry.logger.warn "Could not install #{adapter_name} because it was not found" unless adapter + instrumentation_names.each do |instrumentation_name| + instrumentation = find_instrumentation(instrumentation_name) + OpenTelemetry.logger.warn "Could not install #{instrumentation_name} because it was not found" unless instrumentation - install_adapter(adapter, adapter_config_map[adapter.name]) + install_instrumentation(instrumentation, instrumentation_config_map[instrumentation.name]) end end end # Install all instrumentation available and installable in this process. # - # @param [optional Hash<String, Hash>] adapter_config_map A map of - # adapter_name to config. This argument is optional and config can be - # passed for as many or as few adapters as desired. - def install_all(adapter_config_map = {}) + # @param [optional Hash<String, Hash>] instrumentation_config_map 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. + def install_all(instrumentation_config_map = {}) @lock.synchronize do - @adapters.map(&:instance).each do |adapter| - install_adapter(adapter, adapter_config_map[adapter.name]) + @instrumentation.map(&:instance).each do |instrumentation| + install_instrumentation(instrumentation, instrumentation_config_map[instrumentation.name]) end end end private - def find_adapter(adapter_name) - @adapters.detect { |a| a.instance.name == adapter_name } + def find_instrumentation(instrumentation_name) + @instrumentation.detect { |a| a.instance.name == instrumentation_name } &.instance end - def install_adapter(adapter, config) - if adapter.install(config) - OpenTelemetry.logger.info "Adapter: #{adapter.name} was successfully installed" + def install_instrumentation(instrumentation, config) + if instrumentation.install(config) + OpenTelemetry.logger.info "Instrumentation: #{instrumentation.name} was successfully installed" else - OpenTelemetry.logger.warn "Adapter: #{adapter.name} failed to install" + OpenTelemetry.logger.warn "Instrumentation: #{instrumentation.name} failed to install" end rescue => e # rubocop:disable Style/RescueStandardError - OpenTelemetry.logger.warn "Adapter: #{adapter.name} unhandled exception" \ + OpenTelemetry.logger.warn "Instrumentation: #{instrumentation.name} unhandled exception" \ "during install #{e}: #{e.backtrace}" end end end end