Skip to content

Commit ec1e930

Browse files
committed
Add changes from code review around comments and add test for the new environment variable.
1 parent a66e635 commit ec1e930

File tree

4 files changed

+55
-4
lines changed

4 files changed

+55
-4
lines changed

lib/datadog/core/configuration/settings.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1003,7 +1003,7 @@ def initialize(*_)
10031003
end
10041004
end
10051005

1006-
# Enable experimental process tags propagation.
1006+
# Enable experimental process tags propagation such that payloads like spans contain the process tag.
10071007
#
10081008
# @default `DD_EXPERIMENTAL_PROPAGATE_PROCESS_TAGS_ENABLED` environment variable, otherwise `false`
10091009
# @return [Boolean]

lib/datadog/core/environment/ext.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ module Ext
3333
LANG_INTERPRETER = "#{RUBY_ENGINE}-#{RUBY_PLATFORM}"
3434
LANG_PLATFORM = RUBY_PLATFORM
3535
LANG_VERSION = RUBY_VERSION
36-
PROCESS_TYPE = 'script'
36+
PROCESS_TYPE = 'script' # Out of the options [jar, script, class, executable], we consider Ruby to always be a script
3737
RUBY_ENGINE = ::RUBY_ENGINE # e.g. 'ruby', 'jruby', 'truffleruby'
3838
TAG_ENV = 'env'
3939
TAG_ENTRYPOINT_BASEDIR = "entrypoint.basedir"

lib/datadog/core/environment/process.rb

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,36 +6,48 @@
66
module Datadog
77
module Core
88
module Environment
9-
# Retrieves process level information
9+
# Retrieves process level information such that it can be attached to various payloads
1010
module Process
1111
module_function
1212

13+
# Returns the last segment of the working directory of the process
14+
# @return [String] the last segment of the working directory
1315
def entrypoint_workdir
1416
File.basename(Dir.pwd)
1517
end
1618

19+
# Returns the entrypoint type of the process
20+
# @return [String] the type of the process, which is fixed in Ruby
1721
def entrypoint_type
1822
Core::Environment::Ext::PROCESS_TYPE
1923
end
2024

25+
# Returns the last segment of the base directory of the process
26+
# @return [String] the last segment of base directory of the script
2127
def entrypoint_name
2228
File.basename($0)
2329
end
2430

31+
# Returns the last segment of the base directory of the process
32+
# @return [String] the last segment of the base directory of the script
2533
def entrypoint_basedir
2634
current_basedir = File.expand_path(File.dirname($0))
2735
normalized_basedir = current_basedir.tr(File::SEPARATOR, '/')
2836
normalized_basedir.delete_prefix!('/')
2937
end
3038

31-
# Normalize tag key and value using the Datadog Agent's tag normalization logic
39+
# Normalize tag key and value using the Trace Agent's tag normalization logic
40+
# @param key [String] the original key
41+
# @param value [String] the original value
42+
# @return [String] normalized key:value pair
3243
def serialized_kv_helper(key, value)
3344
key = Core::Normalizer.normalize(key)
3445
value = Core::Normalizer.normalize(value)
3546
"#{key}:#{value}"
3647
end
3748

3849
# This method returns a key/value part of serialized tags in the format of k1:v1,k2:v2,k3:v3
50+
# @return [String] comma-separated normalized key:value pairs
3951
def serialized
4052
return @serialized if defined?(@serialized)
4153
tags = []

spec/datadog/core/configuration/settings_spec.rb

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,6 +1337,45 @@
13371337
end
13381338
end
13391339

1340+
describe '#experimental_propagate_process_tags_enabled' do
1341+
subject(:experimental_propagate_process_tags_enabled) { settings.experimental_propagate_process_tags_enabled }
1342+
1343+
context "when #{Datadog::Core::Environment::Ext::ENV_VERSION}" do
1344+
around do |example|
1345+
ClimateControl.modify('DD_EXPERIMENTAL_PROPAGATE_PROCESS_TAGS_ENABLED' => environment) do
1346+
example.run
1347+
end
1348+
end
1349+
1350+
context 'by default' do
1351+
let(:environment) { nil }
1352+
1353+
it { is_expected.to be false }
1354+
end
1355+
1356+
context 'when set to true' do
1357+
let(:environment) { 'true' }
1358+
1359+
it { is_expected.to be true }
1360+
end
1361+
1362+
context 'when set to false' do
1363+
let(:environment) { 'false' }
1364+
1365+
it { is_expected.to be false }
1366+
end
1367+
end
1368+
end
1369+
1370+
describe '#experimental_propagate_process_tags_enabled=' do
1371+
it 'updates the #experimental_propagate_process_tags_enabled setting' do
1372+
expect { settings.experimental_propagate_process_tags_enabled = true }
1373+
.to change { settings.experimental_propagate_process_tags_enabled }
1374+
.from(false)
1375+
.to(true)
1376+
end
1377+
end
1378+
13401379
describe '#time_now_provider=' do
13411380
subject(:set_time_now_provider) { settings.time_now_provider = time_now_provider }
13421381

0 commit comments

Comments
 (0)