diff --git a/lib/datadog/core/diagnostics/environment_logger.rb b/lib/datadog/core/diagnostics/environment_logger.rb index 005d52f6ce2..3222e5196c4 100644 --- a/lib/datadog/core/diagnostics/environment_logger.rb +++ b/lib/datadog/core/diagnostics/environment_logger.rb @@ -13,6 +13,10 @@ def log_configuration!(prefix, data) logger.info("DATADOG CONFIGURATION - #{prefix} - #{data}") end + def log_debug!(prefix, data) + logger.debug("DATADOG CONFIGURATION - #{prefix} - #{data}") + end + def log_error!(prefix, type, error) logger.warn("DATADOG ERROR - #{prefix} - #{type}: #{error}") end diff --git a/lib/datadog/tracing/diagnostics/environment_logger.rb b/lib/datadog/tracing/diagnostics/environment_logger.rb index cd1a6b22ac7..d96cfa14c65 100644 --- a/lib/datadog/tracing/diagnostics/environment_logger.rb +++ b/lib/datadog/tracing/diagnostics/environment_logger.rb @@ -14,8 +14,8 @@ module EnvironmentLogger def self.collect_and_log!(responses: nil) if log? - env_data = EnvironmentCollector.collect_config! - log_configuration!('TRACING', env_data.to_json) + log_configuration!('TRACING', EnvironmentCollector.collect_config!.to_json) + log_debug!('TRACING INTEGRATIONS', EnvironmentCollector.collect_integrations_settings!.to_json) if responses err_data = EnvironmentCollector.collect_errors!(responses) @@ -40,7 +40,6 @@ def collect_config! sampling_rules: sampling_rules, integrations_loaded: integrations_loaded, partial_flushing_enabled: partial_flushing_enabled, - **instrumented_integrations_settings } end @@ -128,6 +127,18 @@ def partial_flushing_enabled !!Datadog.configuration.tracing.partial_flush.enabled end + def collect_integrations_settings! + instrumented_integrations.each_with_object({}) do |(name, integration), result| + integration.configuration.to_h.each do |setting, value| + next if setting == :tracer # Skip internal objects + + # Convert value to a string to avoid custom #to_json + # handlers possibly causing errors. + result[:"#{name}_#{setting}"] = value.to_s + end + end + end + private def instrumented_integrations @@ -139,19 +150,6 @@ def instrumented_integrations Datadog.configuration.tracing.instrumented_integrations end - - # Capture all active integration settings into "integrationName_settingName: value" entries. - def instrumented_integrations_settings - instrumented_integrations.flat_map do |name, integration| - integration.configuration.to_h.flat_map do |setting, value| - next [] if setting == :tracer # Skip internal Ruby objects - - # Convert value to a string to avoid custom #to_json - # handlers possibly causing errors. - [[:"integration_#{name}_#{setting}", value.to_s]] - end - end.to_h - end end end end diff --git a/spec/datadog/tracing/diagnostics/environment_logger_spec.rb b/spec/datadog/tracing/diagnostics/environment_logger_spec.rb index 32cd92ffefa..22f6a124451 100644 --- a/spec/datadog/tracing/diagnostics/environment_logger_spec.rb +++ b/spec/datadog/tracing/diagnostics/environment_logger_spec.rb @@ -53,6 +53,24 @@ end end + context 'with integrations loaded' do + before { Datadog.configure { |c| c.tracing.instrument :http } } + + it 'logs the integration settings as debug' do + expect(logger).to receive(:debug).with start_with('DATADOG CONFIGURATION - TRACING INTEGRATIONS') do |msg| + json = JSON.parse(msg.partition('- TRACING INTEGRATIONS -')[2].strip) + expect(json).to include( + 'http_analytics_enabled' => 'false', + 'http_analytics_sample_rate' => '1.0', + 'http_distributed_tracing' => 'true', + 'http_split_by_domain' => 'false', + ) + end + + collect_and_log! + end + end + context 'with agent error' do subject(:collect_and_log!) { env_logger.collect_and_log!(responses: [response]) } @@ -188,16 +206,6 @@ is_expected.to include integrations_loaded: end_with("@#{RUBY_VERSION}") end - context 'with integration-specific settings' do - let(:options) { { service_name: 'my-http' } } - - it { is_expected.to include integration_http_analytics_enabled: 'false' } - it { is_expected.to include integration_http_analytics_sample_rate: '1.0' } - it { is_expected.to include integration_http_service_name: 'my-http' } - it { is_expected.to include integration_http_distributed_tracing: 'true' } - it { is_expected.to include integration_http_split_by_domain: 'false' } - end - context 'with partial flushing enabled' do before { expect(Datadog.configuration.tracing.partial_flush).to receive(:enabled).and_return(true) } @@ -206,6 +214,18 @@ end end + describe '#collect_integrations_settings!' do + subject(:collect_config!) { described_class.collect_integrations_settings! } + + before { Datadog.configure { |c| c.tracing.instrument :http, service_name: 'my-http' } } + + it { is_expected.to include http_analytics_enabled: 'false' } + it { is_expected.to include http_analytics_sample_rate: '1.0' } + it { is_expected.to include http_service_name: 'my-http' } + it { is_expected.to include http_distributed_tracing: 'true' } + it { is_expected.to include http_split_by_domain: 'false' } + end + describe '#collect_errors!' do subject(:collect_errors!) { collector.collect_errors!([response]) }