Skip to content

Commit 3a97563

Browse files
committed
make this more concise
1 parent f2af53f commit 3a97563

File tree

1 file changed

+11
-20
lines changed

1 file changed

+11
-20
lines changed

lib/datadog/core/configuration/settings.rb

+11-20
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ def initialize(*_)
621621
o.env_parser do |env_value|
622622
# Parses a string containing key-value pairs and returns a hash.
623623
# Key-value pairs are delimited by ':' OR `=`, and pairs are separated by whitespace, comma, OR BOTH.
624-
values = {}
624+
result = {}
625625
unless env_value.nil? || env_value.empty?
626626
# falling back to comma as separator
627627
sep = env_value.include?(',') ? ',' : ' '
@@ -631,28 +631,19 @@ def initialize(*_)
631631
next if tag.empty?
632632

633633
# tag by : or = (for OpenTelemetry)
634-
key, val = if tag.include?(':')
635-
tag.split(':', 2).map(&:strip)
636-
elsif tag.include?('=')
637-
tag.split('=', 2).map(&:strip)
638-
else
639-
[tag.strip, '']
640-
end
641-
next if key.empty?
642-
634+
key, val = tag.split(/[:=]/, 2).map(&:strip)
635+
val ||= ''
643636
# maps OpenTelemetry semantic attributes to Datadog tags
644-
case key.downcase
645-
when 'deployment.environment'
646-
key = 'env'
647-
when 'service.version'
648-
key = 'version'
649-
when 'service.name'
650-
key = 'service'
651-
end
652-
values[key] = val
637+
key = case key.downcase
638+
when 'deployment.environment' then 'env'
639+
when 'service.version' then 'version'
640+
when 'service.name' then 'service'
641+
else key
642+
end
643+
result[key] = val unless key.empty?
653644
end
654645
end
655-
values
646+
result
656647
end
657648
o.setter do |new_value, old_value|
658649
raw_tags = new_value || {}

0 commit comments

Comments
 (0)