Skip to content

Commit

Permalink
Add a log that states when a dependency isn't found versus installed.
Browse files Browse the repository at this point in the history
Set the log to debug given many dependencies will not be found and
logs become noisy on boot.
  • Loading branch information
cwjenkins committed Oct 18, 2023
1 parent afc7bc5 commit e69bcb3
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 21 deletions.
4 changes: 3 additions & 1 deletion registry/lib/opentelemetry/instrumentation/registry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ def find_instrumentation(instrumentation_name)
end

def install_instrumentation(instrumentation, config)
if instrumentation.install(config)
if !instrumentation.present?
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
OpenTelemetry.logger.warn "Instrumentation: #{instrumentation.name} failed to install"
Expand Down
64 changes: 44 additions & 20 deletions registry/test/opentelemetry/instrumentation/registry_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,22 @@
class FakeInstrumentation
attr_reader :name, :version, :config

def initialize(name, version)
def initialize(name, version, present: true)
@name = name
@version = version
@install = false
@config = nil
@present = present
end

def instance
self
end

def present?
@present
end

def installed?
@install == true
end
Expand Down Expand Up @@ -67,33 +72,52 @@ def install(config)
end

describe '#install_all' do
before do
instrumentations.each { |i| registry.register(i) }
end
describe 'with existing instrumentation' do
before do
instrumentations.each { |i| registry.register(i) }
end

describe 'when using defaults arguments' do
it 'installs all registered instrumentations' do
registry.install_all
describe 'when using defaults arguments' do
it 'installs all registered instrumentations' do
registry.install_all

instrumentations.each do |i|
_(i).must_be :installed?
_(i.config).must_be_nil
end
end
end

instrumentations.each do |i|
_(i).must_be :installed?
_(i.config).must_be_nil
describe 'when using instrumentation specific configs' do
it 'installs all registered instrumentations' do
registry.install_all(
'TestInstrumentation1' => { a: 'a' },
'TestInstrumentation2' => { b: 'b' }
)

_(instrumentation1).must_be :installed?
_(instrumentation1.config).must_equal(a: 'a')

_(instrumentation2).must_be :installed?
_(instrumentation2.config).must_equal(b: 'b')
end
end
end

describe 'when using instrumentation specific configs' do
it 'installs all registered instrumentations' do
registry.install_all(
'TestInstrumentation1' => { a: 'a' },
'TestInstrumentation2' => { b: 'b' }
)
describe 'with non existent instrumentation' do
describe 'suppress not found' do
before do
@log_stream = StringIO.new
OpenTelemetry.logger = ::Logger.new(@log_stream)
OpenTelemetry.logger.level = ::Logger::WARN
end

_(instrumentation1).must_be :installed?
_(instrumentation1.config).must_equal(a: 'a')
it 'suppresses not found in logs' do
registry.register(FakeInstrumentation.new('Not installed', '1.0.0', present: false))
registry.install_all({})

_(instrumentation2).must_be :installed?
_(instrumentation2.config).must_equal(b: 'b')
_(@log_stream.string).must_be_empty
end
end
end
end
Expand Down

0 comments on commit e69bcb3

Please sign in to comment.