Skip to content

Commit

Permalink
chore: Add tests for name and version config
Browse files Browse the repository at this point in the history
  • Loading branch information
kaylareopelle committed May 15, 2024
1 parent fb0b5c8 commit 236bf1f
Showing 1 changed file with 40 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
let(:log_stream) { StringIO.new }
let(:ruby_logger) { Logger.new(log_stream) }
let(:msg) { 'message' }
let(:config) { {} }

before do
exporter.reset
instrumentation.install
instrumentation.install(config)
end

after { instrumentation.instance_variable_set(:@installed, false) }
Expand All @@ -35,9 +36,44 @@
assert_equal(OpenTelemetry::Instrumentation::Logger::VERSION, log_record.instrumentation_scope.version)
end

it 'sets the OTel logger instrumentation name and version (user defined)' do
ruby_logger.debug(msg)
skip 'TODO: write tests for configuration options'
describe 'configuration options' do
describe 'when a user configures name' do
let(:config) { { name: 'custom_logger' } }

it 'updates the logger name' do
ruby_logger.debug(msg)
assert_equal('custom_logger', log_record.instrumentation_scope.name)
end

it 'uses the default version' do
ruby_logger.debug(msg)
assert_equal(OpenTelemetry::Instrumentation::Logger::VERSION, log_record.instrumentation_scope.version)
end
end

describe 'when a user configures version' do
let(:config) { { version: '5000' } }

it 'updates the logger version' do
ruby_logger.debug(msg)
assert_equal('5000', log_record.instrumentation_scope.version)
end

it 'uses the default name' do
ruby_logger.debug(msg)
assert_equal(OpenTelemetry::Instrumentation::Logger::NAME, log_record.instrumentation_scope.name)
end
end

describe 'when a user configures both name and version' do
let(:config) { { name: 'custom_logger', version: '5000'} }

it 'updates both values' do
ruby_logger.debug(msg)
assert_equal('custom_logger', log_record.instrumentation_scope.name)
assert_equal('5000', log_record.instrumentation_scope.version)
end
end
end

it 'sets log record attributes based on the Ruby log' do
Expand Down

0 comments on commit 236bf1f

Please sign in to comment.