Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make use_all config friendlier #1406

Merged
merged 1 commit into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading