Skip to content

Commit f85f2c0

Browse files
authored
Remove logger_without_configuration call in logger_without_components (#4639)
1 parent 20efc6c commit f85f2c0

File tree

2 files changed

+25
-49
lines changed

2 files changed

+25
-49
lines changed

lib/datadog/core/configuration.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,6 @@ def replace_components!(settings, old)
278278
def logger_without_components
279279
# Use default logger without initializing components.
280280
# This enables logging during initialization, otherwise we'd run into deadlocks.
281-
return logger_without_configuration unless configuration?
282281

283282
@temp_logger ||= begin
284283
logger = configuration.logger.instance || Core::Logger.new($stdout)
@@ -290,9 +289,14 @@ def logger_without_components
290289
def logger_without_configuration
291290
# There's rare cases where we need to use logger during configuration initialization,
292291
# such as reading stable config. In this case we cannot access configuration.
292+
293293
@temp_config_logger ||= begin
294+
debug_env_value = ENV[Ext::Diagnostics::ENV_DEBUG_ENABLED]&.strip&.downcase
295+
debug_value = debug_env_value == 'true' || debug_env_value == '1' # rubocop:disable Style/MultipleComparison
296+
294297
logger = Core::Logger.new($stdout)
295-
logger.level = ::Logger::DEBUG
298+
# We cannot access config and the default level is INFO, so we need to set the level manually
299+
logger.level = debug_value ? ::Logger::DEBUG : ::Logger::INFO
296300
logger
297301
end
298302
end

spec/datadog/core/configuration_spec.rb

Lines changed: 19 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -407,61 +407,16 @@
407407
subject(:logger) { test_class.logger }
408408

409409
it { is_expected.to be_a_kind_of(Datadog::Core::Logger) }
410+
it { expect(logger.level).to be ::Logger::INFO }
410411

411-
it 'has the default log level' do
412-
# If configuration is not initialized, and components neither, we create a temporary logger with debug level
413-
# In order to test that the default log level is INFO, we need to ensure that configuration is initialized.
414-
test_class.configuration
415-
416-
expect(logger.level).to be default_log_level
417-
end
418-
419-
context 'when components are not initialized but configuration is' do
420-
before do
421-
test_class.configuration
422-
end
423-
424-
it 'calls logger_without_components' do
425-
expect(test_class).to receive(:logger_without_components)
426-
427-
logger
428-
end
429-
430-
it 'does not call logger_without_configuration' do
431-
expect(test_class).to_not receive(:logger_without_configuration)
432-
433-
logger
434-
end
435-
412+
context 'when components are not initialized' do
436413
it 'does not cause them to be initialized' do
437414
logger
438415

439416
expect(test_class.send(:components?)).to be false
440417
end
441418
end
442419

443-
context 'when configuration is not initialized' do
444-
it { expect(logger.level).to be ::Logger::DEBUG }
445-
446-
it 'calls logger_without_configuration' do
447-
expect(test_class).to receive(:logger_without_configuration)
448-
449-
logger
450-
end
451-
452-
it 'does not call configuration' do
453-
expect(test_class).to_not receive(:configuration)
454-
455-
logger
456-
end
457-
458-
it 'returns a logger without configuration' do
459-
logger
460-
461-
expect(logger).to be_a_kind_of(Datadog::Core::Logger)
462-
end
463-
end
464-
465420
context 'when components are being replaced' do
466421
before do
467422
test_class.configure {}
@@ -485,6 +440,23 @@
485440
end
486441
end
487442

443+
describe '#logger_without_configuration' do
444+
subject(:logger_without_configuration) { test_class.send(:logger_without_configuration) }
445+
context 'when configuration is not initialized and DD_TRACE_DEBUG is not set' do
446+
it { expect(logger_without_configuration.level).to be ::Logger::INFO }
447+
end
448+
449+
context 'when configuration is not initialized and DD_TRACE_DEBUG is set' do
450+
around do |example|
451+
ClimateControl.modify('DD_TRACE_DEBUG' => 'true') do
452+
example.run
453+
end
454+
end
455+
456+
it { expect(logger_without_configuration.level).to be ::Logger::DEBUG }
457+
end
458+
end
459+
488460
describe '#runtime_metrics' do
489461
subject(:runtime_metrics) { test_class.send(:components).runtime_metrics }
490462

0 commit comments

Comments
 (0)