-
Notifications
You must be signed in to change notification settings - Fork 397
feat: add process tags to traces #5033
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
Merged
+695
−2
Merged
Changes from 32 commits
Commits
Show all changes
82 commits
Select commit
Hold shift + click to select a range
1d8bab2
Add initial attempt at adding process related tags on trace payloads.…
wantsui 58592a3
Add test for multiple calls to the formatter tags
wantsui 7dc9184
Add tests for trace formatter spec to assert that the first span of t…
wantsui cad26a6
it turns out you cannot just pin things to rails 7 due to newer ruby …
wantsui f31440a
Update lib/datadog/core/environment/process.rb
wantsui cfec602
fix string and rename formatted_process_tags_k1_v1 to serialized
wantsui 8dae705
remove unneeded line
wantsui 055586f
remove server type for now until more research is done
wantsui cacb500
Add new tag normalizer logic following the trace agent.
wantsui 7661a3f
lint fix
wantsui 7825940
add missing files from prototype command
wantsui 5de6efd
Add missing constants to ext rbs file
wantsui f5ca84a
jruby fix for the process spec
wantsui 9ad5be5
remove the active record during rails creation because it caused a jr…
wantsui a66e635
Bring tag normalization to 1:1 parity with the Trace Agent
wantsui ec1e930
Add changes from code review around comments and add test for the new…
wantsui 4073ab5
Merge branch 'master' into add-process-tags-to-tracing
wantsui 22a3680
Remove the rails gem install from process_spec
wantsui 5784833
Remove 1 sec delay.
wantsui 2b705e3
Update sig/datadog/core/environment/ext.rbs
wantsui e3deb4c
Update lib/datadog/tracing/transport/trace_formatter.rb
wantsui 4747259
Add improvements for long strings.
wantsui 41bc6c0
small improvement to the whitespace removal.
wantsui c3605c0
Add upper bound to regex to avoid the polynomial regex on uncontrolle…
wantsui adfa416
Change untyped to string.
wantsui 0dff545
Use possessive quantifiers in regex instead of limiting the upper bou…
wantsui 7d8da40
Fix types for steep check command
wantsui 31d9796
Remove unneeded Core prefix
wantsui 3672a8a
lint fixes
wantsui 23d9769
restructure folder lookup so it works on the macos ci tests
wantsui 7615906
fixes for local mac development.
wantsui d4c6a91
Add missing trace agent test cases.
wantsui 433b250
Fix lint
wantsui 47efb90
Change methods to private. Also add comments with examples
wantsui a2643a6
Fix basedir logic and adjust tests (and also fix the private change)
wantsui ccd4971
Fix steepcheck error
wantsui be9587d
Add in byte logic to handle emojis with early backoff and allow start…
wantsui 6042830
Move process tags only to the first span and adjust tests
wantsui 4210d74
Add a special character into the test app name to show that it gets n…
wantsui f9af946
Update lib/datadog/core/normalizer.rb
wantsui 381fbe2
Update lib/datadog/core/normalizer.rb
wantsui 138dff8
Fixes for new constant names
wantsui 2449153
Change to byteslice
wantsui 5252259
fix lint.
wantsui 0eaf302
remove process_spec from main rake task
wantsui fbfecfe
Update spec/datadog/core/normalizer_spec.rb
wantsui cc2225f
Update spec/datadog/tracing/transport/trace_formatter_spec.rb
wantsui 62822ab
Merge branch 'master' into add-process-tags-to-tracing
wantsui a77e63b
Remove the unless check and replace with an assertion that the file e…
wantsui 439e81a
Update spec/datadog/core/environment/process_spec.rb
wantsui 9e45ade
fix lint
wantsui 0ab4fef
Rename Normalizer to TagNormalizer.
wantsui 6577d3f
Update lib/datadog/core/environment/process.rb
wantsui a336c66
Add api private comment to the tag normalizer and refactor away the e…
wantsui 0d229de
Fix steep errors on the process rbs file
wantsui e83bc4a
Refactor the utils encode call so it can be used in the tag normalize…
wantsui ce1759f
Update Rakefile
wantsui 8b978c6
Update lib/datadog/core/tag_normalizer.rb
wantsui f4c9d49
Add lint fixes and remove unneeded regex at the end.
wantsui eae4eb9
fix rbs file for deleted variable
wantsui f3f1480
remove unneeded conditional
wantsui b48d20d
Add a log if the process tags cannot be obtained
wantsui 3d33291
Fix regex and reuse the same test cases to show that the leading digi…
wantsui 4e3f8f4
Attempt to retrieve as many non empty string process tags as possible…
wantsui 5f6908c
Fix hard to spot missing comma in Rakefile that was breaking tests
wantsui 29ea669
Update lib/datadog/core/environment/process.rb
wantsui 3b35388
Remove the usage of utils from the tag normalizer until 3.0 due to th…
wantsui 856d0e6
Add tests to show the values based on different 0 overrides.
wantsui 77e4e51
Fix test string.
wantsui 330219a
refactor out the rescue and process and update the test
wantsui 19e3bc2
Fix mocking.
wantsui d24d98b
Update Matrixfile
wantsui d3a4ca2
Merge branch 'master' into add-process-tags-to-tracing
wantsui 5c12b52
Do not run tests for all ruby versions.
wantsui 1d61402
Update lib/datadog/core/environment/process.rb
wantsui cba300e
Update lib/datadog/core/environment/process.rb
wantsui 5cae372
Add a foo bar test condition with colons and commas, which revealed a…
wantsui b52e3f6
Merge branch 'master' into add-process-tags-to-tracing
marcotc e0bfe8c
use around syntax
p 6c872a0
Update lib/datadog/core/tag_normalizer.rb
marcotc 01ac7b0
Update lib/datadog/core/tag_normalizer.rb
marcotc 50d3392
Rename process_values_normalize to normalize_process_value and adjust…
wantsui File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require_relative 'ext' | ||
| require_relative '../normalizer' | ||
|
|
||
| module Datadog | ||
| module Core | ||
| module Environment | ||
| # Retrieves process level information such that it can be attached to various payloads | ||
wantsui marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| module Process | ||
| module_function | ||
|
|
||
| # Returns the last segment of the working directory of the process | ||
| # @return [String] the last segment of the working directory | ||
| def entrypoint_workdir | ||
marcotc marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| File.basename(Dir.pwd) | ||
| end | ||
|
|
||
| # Returns the entrypoint type of the process | ||
| # @return [String] the type of the process, which is fixed in Ruby | ||
| def entrypoint_type | ||
| Environment::Ext::PROCESS_TYPE | ||
| end | ||
|
|
||
| # Returns the last segment of the base directory of the process | ||
| # @return [String] the last segment of base directory of the script | ||
wantsui marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| def entrypoint_name | ||
| File.basename($0) | ||
p-datadog marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| end | ||
|
|
||
| # Returns the last segment of the base directory of the process | ||
| # @return [String] the last segment of the base directory of the script | ||
wantsui marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| def entrypoint_basedir | ||
marcotc marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| current_basedir = File.expand_path(File.dirname($0)) | ||
| normalized_basedir = current_basedir.tr(File::SEPARATOR, '/') | ||
wantsui marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
wantsui marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| normalized_basedir.delete_prefix('/') | ||
| end | ||
|
|
||
| # Normalize tag key and value using the Trace Agent's tag normalization logic | ||
| # @param key [String] the original key | ||
| # @param value [String] the original value | ||
| # @return [String] normalized key:value pair | ||
| def serialized_kv_helper(key, value) | ||
| key = Normalizer.normalize(key) | ||
| value = Normalizer.normalize(value) | ||
| "#{key}:#{value}" | ||
| end | ||
|
|
||
| # This method returns a key/value part of serialized tags in the format of k1:v1,k2:v2,k3:v3 | ||
| # @return [String] comma-separated normalized key:value pairs | ||
| def serialized | ||
| return @serialized if defined?(@serialized) | ||
| tags = [] | ||
| tags << serialized_kv_helper(Environment::Ext::TAG_ENTRYPOINT_WORKDIR, entrypoint_workdir) if entrypoint_workdir | ||
| tags << serialized_kv_helper(Environment::Ext::TAG_ENTRYPOINT_NAME, entrypoint_name) if entrypoint_name | ||
| tags << serialized_kv_helper(Environment::Ext::TAG_ENTRYPOINT_BASEDIR, entrypoint_basedir) if entrypoint_basedir | ||
| tags << serialized_kv_helper(Environment::Ext::TAG_ENTRYPOINT_TYPE, entrypoint_type) if entrypoint_type | ||
| @serialized = tags.join(',').freeze | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| module Datadog | ||
| module Core | ||
| module Normalizer | ||
wantsui marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
wantsui marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| module_function | ||
|
|
||
| INVALID_TAG_CHARACTERS = %r{[^\p{L}0-9_\-:./]} | ||
| LEADING_INVALID_CHARS = %r{\A[^\p{L}:]++} | ||
| TRAILING_UNDERSCORES = %r{_++\z} | ||
| MAX_CHARACTER_LENGTH = 200 | ||
|
|
||
| # Based on https://github.com/DataDog/datadog-agent/blob/45799c842bbd216bcda208737f9f11cade6fdd95/pkg/trace/traceutil/normalize.go#L131 | ||
| # Specifically: | ||
| # - Must be valid UTF-8 | ||
| # - Invalid characters are replaced with an underscore | ||
| # - Leading non-letter characters are removed but colons are kept | ||
| # - Trailing non-letter characters are removed | ||
| # - Trailing underscores are removed | ||
| # - Consecutive underscores are merged into a single underscore | ||
| # - Maximum length is 200 characters | ||
| def self.normalize(original_value) | ||
wantsui marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| normalized_value = original_value.to_s.encode('UTF-8', invalid: :replace, undef: :replace) | ||
| normalized_value.strip! | ||
| return "" if normalized_value.empty? | ||
|
|
||
| normalized_value.downcase! | ||
| normalized_value.gsub!(INVALID_TAG_CHARACTERS, '_') | ||
| normalized_value.sub!(LEADING_INVALID_CHARS, "") | ||
| normalized_value.sub!(TRAILING_UNDERSCORES, "") | ||
wantsui marked this conversation as resolved.
Fixed
Show fixed
Hide fixed
|
||
| normalized_value.squeeze!('_') if normalized_value.include?('__') | ||
| normalized_value.slice!(MAX_CHARACTER_LENGTH..-1) if normalized_value.length > MAX_CHARACTER_LENGTH | ||
wantsui marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| normalized_value | ||
| end | ||
| end | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| module Datadog | ||
| module Core | ||
| module Environment | ||
| module Process | ||
| @serialized: ::String | ||
|
|
||
| def self?.entrypoint_workdir: () -> ::String | ||
|
|
||
| def self?.entrypoint_type: () -> ::String | ||
|
|
||
| def self?.entrypoint_name: () -> ::String | ||
|
|
||
| def self?.entrypoint_basedir: () -> ::String | ||
| def self?.serialized_kv_helper: (::String key, ::String value) -> ::String | ||
wantsui marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| def self?.serialized: () -> ::String | ||
| end | ||
| end | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| module Datadog | ||
| module Core | ||
| module Normalizer | ||
| INVALID_TAG_CHARACTERS: ::Regexp | ||
| LEADING_INVALID_CHARS: ::Regexp | ||
| TRAILING_UNDERSCORES: ::Regexp | ||
| MAX_CHARACTER_LENGTH: ::Integer | ||
| def self.normalize: (untyped original_value) -> ::String | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.