Skip to content

Commit

Permalink
DEBUG-3328 report DI status in environment logger summary (#4285)
Browse files Browse the repository at this point in the history
  • Loading branch information
p-datadog authored Jan 14, 2025
1 parent b2bf14b commit 8f97fe7
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/datadog/core/configuration/components.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ def initialize(settings)
@health_metrics = self.class.build_health_metrics(settings)
@appsec = Datadog::AppSec::Component.build_appsec_component(settings, telemetry: telemetry)
@dynamic_instrumentation = Datadog::DI::Component.build(settings, agent_settings, @logger, telemetry: telemetry)
@environment_logger_extra[:dynamic_instrumentation_enabled] = !!@dynamic_instrumentation

self.class.configure_tracing(settings)
end
Expand Down
54 changes: 53 additions & 1 deletion spec/datadog/core/configuration/components_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'spec_helper'
require 'datadog/di/spec_helper'
require 'datadog/profiling/spec_helper'

require 'logger'
Expand Down Expand Up @@ -95,6 +96,54 @@
expect(components.runtime_metrics).to be runtime_metrics
expect(components.health_metrics).to be health_metrics
end

describe '@environment_logger_extra' do
let(:environment_logger_extra) { {} }

let(:extra) do
components.instance_variable_get('@environment_logger_extra')
end

context 'DI is not enabled' do
it 'reports DI as disabled' do
expect(components.dynamic_instrumentation).to be nil
expect(extra).to eq(dynamic_instrumentation_enabled: false)
end
end

context 'DI is enabled' do
before(:all) do
skip 'DI is disabled due to Ruby version < 2.5' if RUBY_VERSION < '2.6'
end

before do
settings.dynamic_instrumentation.enabled = true
end

context 'MRI' do
before(:all) do
skip 'Test requires MRI' if PlatformHelpers.jruby?
end

it 'reports DI as enabled' do
expect(components.dynamic_instrumentation).to be_a(Datadog::DI::Component)
expect(extra).to eq(dynamic_instrumentation_enabled: true)
end
end

context 'JRuby' do
before(:all) do
skip 'Test requires JRuby' unless PlatformHelpers.jruby?
end

it 'reports DI as disabled' do
expect(logger).to receive(:warn).with(/cannot enable dynamic instrumentation/)
expect(components.dynamic_instrumentation).to be nil
expect(extra).to eq(dynamic_instrumentation_enabled: false)
end
end
end
end
end

describe '::build_health_metrics' do
Expand Down Expand Up @@ -1132,7 +1181,10 @@
expect(Datadog::Profiling::Component).to receive(:build_profiler_component)
.and_return([nil, environment_logger_extra])

expect(Datadog::Core::Diagnostics::EnvironmentLogger).to receive(:collect_and_log!).with(environment_logger_extra)
expect(Datadog::Core::Diagnostics::EnvironmentLogger).to \
receive(:collect_and_log!).with(
environment_logger_extra.merge(dynamic_instrumentation_enabled: false)
)

startup!
end
Expand Down

0 comments on commit 8f97fe7

Please sign in to comment.