Skip to content
Open
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
9 changes: 9 additions & 0 deletions lib/datadog/lambda.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ def self.configure_apm
# Needed to keep trace flushes on a single line
$stdout.sync = true

# The extension forwards feature flag config requests with the API key it
# resolved (e.g. from DD_API_KEY_SECRET_ARN). Only use it when DD_API_KEY is
# unset: an extension without that route returns 404, and the tracer does
# not fall back to the default endpoint.
ff_url = 'DD_FEATURE_FLAGS_CONFIGURATION_SOURCE_AGENTLESS_BASE_URL'
if Datadog::Utils.extension_running? && ENV['DD_API_KEY'].to_s.strip.empty? && ENV[ff_url].to_s.strip.empty?
ENV[ff_url] = 'http://127.0.0.1:8126'
end

Datadog.configure do |c|
unless Datadog::Utils.extension_running?
c.tracing.writer = Datadog::Tracing::SyncWriter.new(
Expand Down
23 changes: 23 additions & 0 deletions test/datadog/lambda.spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,29 @@
# rubocop:enable Metrics/LineLength
end
end

describe '#configure_apm feature flags base URL' do
ff_url = 'DD_FEATURE_FLAGS_CONFIGURATION_SOURCE_AGENTLESS_BASE_URL'
[
[true, {}, 'http://127.0.0.1:8126'],
[true, { 'DD_API_KEY' => '' }, 'http://127.0.0.1:8126'],
[true, { 'DD_API_KEY' => ' ' }, 'http://127.0.0.1:8126'],
[true, { 'DD_API_KEY_SECRET_ARN' => 'arn' }, 'http://127.0.0.1:8126'],
[true, { 'DD_API_KEY' => 'key' }, nil],
[true, { ff_url => 'http://custom' }, 'http://custom'],
[false, {}, nil]
].each do |extension, env, expected|
it "extension=#{extension} env=#{env} sets #{expected.inspect}" do
stub_const('ENV', env.dup)
allow(Datadog::Utils).to receive(:extension_running?).and_return(extension)
allow(Datadog).to receive(:configure)

Datadog::Lambda.configure_apm

expect(ENV[ff_url]).to eq(expected)
end
end
end
end

# rubocop:enable Metrics/BlockLength
Loading