Skip to content

Commit a77e63b

Browse files
committed
Remove the unless check and replace with an assertion that the file exist, small fixes, and add comments to the normalizer.rb explaining the expected usage
1 parent 62822ab commit a77e63b

File tree

5 files changed

+12
-9
lines changed

5 files changed

+12
-9
lines changed

lib/datadog/core/normalizer.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@
33
module Datadog
44
module Core
55
module Normalizer
6+
# Normalization logic used for tag keys and values that the Trace Agent has for traces
7+
# Useful for ensuring that tag keys and values are normalized consistently
8+
# An use case for now is Process Tags which need to be sent across various intakes (profiling, tracing, etc.) consistently
9+
610
module_function
711

812
INVALID_TAG_CHARACTERS = %r{[^\p{L}0-9_\-:./]}
913
LEADING_INVALID_CHARS_NO_DIGITS = %r{\A[^\p{L}:]++}
1014
LEADING_INVALID_CHARS_WITH_DIGITS = %r{\A[^\p{L}0-9:./\-]++}
11-
MAX_BYTE_SIZE = 200
12-
MAX_BYTE_SIZE_BUFFER = MAX_BYTE_SIZE * 2
15+
MAX_BYTE_SIZE = 200 # Represents the max tag length
1316
TRAILING_UNDERSCORES = %r{_++\z}
1417
VALID_ASCII_TAG = %r{\A[a-z:][a-z0-9:./-]*\z}
1518

@@ -23,6 +26,9 @@ module Normalizer
2326
# - Consecutive underscores are merged into a single underscore
2427
# - Maximum length is 200 characters
2528
# If it's a tag value, allow it to start with a digit
29+
# @param original_value [String] The original string
30+
# @param remove_digit_start_char [Boolean] - whether to remove the leading digit (currently only used for tag values)
31+
# @return [String] The normalized string
2632
def self.normalize(original_value, remove_digit_start_char: false)
2733
transformed_value = original_value.to_s.encode('UTF-8', invalid: :replace, undef: :replace)
2834
transformed_value.strip!

sig/datadog/core/normalizer.rbs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ module Datadog
66
LEADING_INVALID_CHARS_WITH_DIGITS: ::Regexp
77
TRAILING_UNDERSCORES: ::Regexp
88
MAX_BYTE_SIZE: ::Integer
9-
MAX_BYTE_SIZE_BUFFER: ::Integer
109
VALID_ASCII_TAG: ::Regexp
1110

1211
def self.normalize: (untyped original_value, ?remove_digit_start_char: bool) -> ::String

spec/datadog/core/environment/process_spec.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,8 @@
2424
Dir.mktmpdir do |tmp_dir|
2525
Dir.chdir(tmp_dir) do
2626
Bundler.with_unbundled_env do
27-
_, stderr, status = Open3.capture3('rails new test@_app --minimal --skip-active-record --skip-test --skip-keeps --skip-git --skip-docker')
28-
unless status.success? && File.exist?("test@_app/Gemfile")
29-
skip("rails new failed: #{stderr}")
30-
end
27+
_, _, _ = Open3.capture3('rails new test@_app --minimal --skip-active-record --skip-test --skip-keeps --skip-git --skip-docker')
28+
expect(File.exist?("test@_app/Gemfile")).to be true
3129
end
3230

3331
File.open("test@_app/Gemfile", 'a') do |file|

spec/datadog/core/normalizer_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
end
5757
end
5858
end
59-
59+
6060
describe 'Follows the normalization logic from the Trace Agent for tag values' do
6161
test_cases = [
6262
{in: '1test', out: '1test'},

spec/datadog/tracing/transport/trace_formatter_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@
243243
expect(first_span.meta).to include(Datadog::Core::Environment::Ext::TAG_PROCESS_TAGS)
244244
expect(first_span.meta[Datadog::Core::Environment::Ext::TAG_PROCESS_TAGS]).to eq(Datadog::Core::Environment::Process.serialized)
245245
end
246-
246+
247247
it 'does not add process tags to non first spans' do
248248
format!
249249
trace.spans.each_with_index do |span, index|

0 commit comments

Comments
 (0)