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

DEBUG-3328 report DI status in environment logger summary #4285

Merged
merged 7 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
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
Loading