Skip to content

Commit

Permalink
Use log level instead of a flag
Browse files Browse the repository at this point in the history
  • Loading branch information
cwjenkins committed Mar 13, 2023
1 parent 2222772 commit a2fc833
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
12 changes: 5 additions & 7 deletions registry/lib/opentelemetry/instrumentation/registry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def install(instrumentation_names, instrumentation_config_map = {})
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], false)
install_instrumentation(instrumentation, instrumentation_config_map[instrumentation.name])
end
end
end
Expand All @@ -59,12 +59,10 @@ def install(instrumentation_names, instrumentation_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.
# @param [optional boolean] suppress_not_found A flag that will suppress
# the warning log that a given instrumentation wasn't found.
def install_all(instrumentation_config_map = {}, suppress_not_found: false)
def install_all(instrumentation_config_map = {})
@lock.synchronize do
@instrumentation.map(&:instance).each do |instrumentation|
install_instrumentation(instrumentation, instrumentation_config_map[instrumentation.name], suppress_not_found)
install_instrumentation(instrumentation, instrumentation_config_map[instrumentation.name])
end
end
end
Expand All @@ -76,9 +74,9 @@ def find_instrumentation(instrumentation_name)
&.instance
end

def install_instrumentation(instrumentation, config, suppress_not_found)
def install_instrumentation(instrumentation, config)
if !instrumentation.present?
OpenTelemetry.logger.warn "Instrumentation: #{instrumentation.name} skipping install given corresponding dependency not found" unless suppress_not_found
OpenTelemetry.logger.debug "Instrumentation: #{instrumentation.name} skipping install given corresponding dependency not found"
elsif instrumentation.install(config)
OpenTelemetry.logger.info "Instrumentation: #{instrumentation.name} was successfully installed with the following options #{instrumentation.config}"
else
Expand Down
3 changes: 2 additions & 1 deletion registry/test/opentelemetry/instrumentation/registry_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,12 @@ def install(config)
before do
@log_stream = StringIO.new
OpenTelemetry.logger = ::Logger.new(@log_stream)
OpenTelemetry.logger.level = ::Logger::WARN
end

it 'suppresses not found in logs' do
registry.register(FakeInstrumentation.new('Not installed', '1.0.0', present: false))
registry.install_all({}, suppress_not_found: true)
registry.install_all({})

_(@log_stream.string).must_be_empty
end
Expand Down
7 changes: 2 additions & 5 deletions sdk/lib/opentelemetry/sdk/configurator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,9 @@ def use(instrumentation_name, config = nil)
#
# @param [optional Hash<String,Hash>] instrumentation_config_map A map with string keys
# representing the instrumentation name and values specifying the instrumentation config
# @param [optional boolean] suppress_not_found A flag that will suppress
# the warning log that a given instrumentation wasn't found.
def use_all(instrumentation_config_map = {}, suppress_not_found = false)
def use_all(instrumentation_config_map = {})
check_use_mode!(USE_MODE_ALL)
@instrumentation_config_map = instrumentation_config_map
@suppress_not_found = suppress_not_found
end

# Add a span processor to the export pipeline
Expand Down Expand Up @@ -166,7 +163,7 @@ def install_instrumentation
when USE_MODE_ONE
OpenTelemetry::Instrumentation.registry.install(@instrumentation_names, @instrumentation_config_map)
when USE_MODE_ALL
OpenTelemetry::Instrumentation.registry.install_all(@instrumentation_config_map, suppress_not_found: @suppress_not_found)
OpenTelemetry::Instrumentation.registry.install_all(@instrumentation_config_map)
end
end

Expand Down

0 comments on commit a2fc833

Please sign in to comment.