Skip to content

Commit

Permalink
Suppress startup logs in test and development environments
Browse files Browse the repository at this point in the history
  • Loading branch information
marcotc committed Aug 8, 2024
1 parent acd9271 commit 55b58d2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 25 deletions.
5 changes: 4 additions & 1 deletion lib/datadog/core/diagnostics/environment_logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ module Datadog
module Core
module Diagnostics
# Base class for EnvironmentLoggers - should allow for easy reporting by users to Datadog support.
#
# The EnvironmentLogger should not pollute the logs in a development environment.
module EnvironmentLogging
def log_configuration!(prefix, data)
logger.info("DATADOG CONFIGURATION - #{prefix} - #{data}")
Expand All @@ -31,7 +33,8 @@ def logger
def log?
startup_logs_enabled = Datadog.configuration.diagnostics.startup_logs.enabled
if startup_logs_enabled.nil?
!repl? && !rspec? # Suppress logs if we are running in a REPL or rspec
# Do not pollute the logs in a development environment.
!Datadog::Core::Environment::Execution.development?
else
startup_logs_enabled
end
Expand Down
18 changes: 4 additions & 14 deletions spec/datadog/core/diagnostics/environment_logger_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
end

describe '#collect_and_log!' do
include_context 'non-development execution environment'

subject(:collect_and_log!) { env_logger.collect_and_log! }

let(:logger) { instance_double(Datadog::Core::Logger) }
Expand Down Expand Up @@ -56,22 +58,10 @@
end
end

context 'under a REPL' do
around do |example|
begin
original = $PROGRAM_NAME
$0 = 'irb'
example.run
ensure
$0 = original
end
end
context 'in a development execution environment' do
before { allow(Datadog::Core::Environment::Execution).to receive(:development?).and_return(true) }

context 'with default settings' do
before do
allow(env_logger).to receive(:rspec?).and_return(true) # Prevent rspec from logging
end

it { expect(logger).to_not have_received(:info) }
end

Expand Down
14 changes: 4 additions & 10 deletions spec/datadog/tracing/diagnostics/environment_logger_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
end

describe '#collect_and_log!' do
include_context 'non-development execution environment'

subject(:collect_and_log!) { env_logger.collect_and_log! }

let(:logger) { instance_double(Datadog::Core::Logger) }
Expand Down Expand Up @@ -91,16 +93,8 @@
end
end

context 'under a REPL' do
around do |example|
begin
original = $PROGRAM_NAME
$0 = 'irb'
example.run
ensure
$0 = original
end
end
context 'in a development execution environment' do
before { allow(Datadog::Core::Environment::Execution).to receive(:development?).and_return(true) }

context 'with default settings' do
before do
Expand Down

0 comments on commit 55b58d2

Please sign in to comment.