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

Disable Telemetry and Remote Configuration in development environments #3039

Merged
merged 5 commits into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
27 changes: 25 additions & 2 deletions lib/datadog/core/configuration/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

require_relative 'base'
require_relative 'ext'
require_relative '../environment/execution'
require_relative '../environment/ext'
require_relative '../runtime/ext'
require_relative '../telemetry/ext'
Expand Down Expand Up @@ -559,10 +560,21 @@ def initialize(*_)
#
# @default `DD_INSTRUMENTATION_TELEMETRY_ENABLED` environment variable, otherwise `true`.
# Can be disabled as documented [here](https://docs.datadoghq.com/tracing/configure_data_security/#telemetry-collection).
# By default, telemetry is disabled in development environments.
# @return [Boolean]
option :enabled do |o|
o.env Core::Telemetry::Ext::ENV_ENABLED
o.default true
o.default do
if Datadog::Core::Environment::Execution.development?
Datadog.logger.debug do
'Development environment detected, disabling Telemetry. ' \
'You can enable it with DD_INSTRUMENTATION_TELEMETRY_ENABLED=true.'
end
false
else
true
end
end
o.type :bool
end

Expand All @@ -586,10 +598,21 @@ def initialize(*_)
# Enable remote configuration. This allows fetching of remote configuration for live updates.
#
# @default `DD_REMOTE_CONFIGURATION_ENABLED` environment variable, otherwise `true`.
# By default, remote configuration is disabled in development environments.
# @return [Boolean]
option :enabled do |o|
o.env Core::Remote::Ext::ENV_ENABLED
o.default true
o.default do
if Datadog::Core::Environment::Execution.development?
Datadog.logger.debug do
'Development environment detected, disabling Remote Configuration. ' \
'You can enable it with DD_REMOTE_CONFIGURATION_ENABLED=true.'
end
false
else
true
end
end
o.type :bool
end

Expand Down
22 changes: 20 additions & 2 deletions spec/datadog/core/configuration/settings_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1236,7 +1236,15 @@
context 'is not defined' do
let(:env_var_value) { nil }

it { is_expected.to be true }
context 'in a development environment' do
it { is_expected.to be false }
end

context 'not in a development environment' do
before { allow(Datadog::Core::Environment::Execution).to receive(:development?).and_return(false) }

it { is_expected.to be true }
end
end

[true, false].each do |value|
Expand Down Expand Up @@ -1305,7 +1313,15 @@
context 'is not defined' do
let(:environment) { nil }

it { is_expected.to be true }
context 'in a development environment' do
it { is_expected.to be false }
end

context 'not in a development environment' do
before { allow(Datadog::Core::Environment::Execution).to receive(:development?).and_return(false) }

it { is_expected.to be true }
end
end

context 'is defined' do
Expand All @@ -1317,6 +1333,8 @@
end

describe '#enabled=' do
before { allow(Datadog::Core::Environment::Execution).to receive(:development?).and_return(false) }

it 'updates the #enabled setting' do
expect { settings.remote.enabled = false }
.to change { settings.remote.enabled }
Expand Down