-
Notifications
You must be signed in to change notification settings - Fork 4
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
[SDTEST-1129] Internal: decouple patcher from tracing, update ruby 3.4 compatibility #252
Merged
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d0c0022
migrate Patcher code to this gem
anmarchenko 8c373a0
fix patch_name and type checking
anmarchenko fa98577
change overly verbose logs expectations in tests that started to fail…
anmarchenko 6e715e9
exclude cucumber versions < 9.0 from Ruby 3.4 testing
anmarchenko 836368d
remove everything that has cucumber from Ruby 3.4 until the keywords …
anmarchenko 3e297cd
fix overly verbose assertions for warning logs
anmarchenko 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
There are no files selected for viewing
This file contains 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 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 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,64 @@ | ||
# frozen_string_literal: true | ||
|
||
require "datadog/core/utils/only_once" | ||
require "datadog/core/telemetry/logger" | ||
|
||
module Datadog | ||
module CI | ||
module Contrib | ||
# Common behavior for patcher modules. | ||
module Patcher | ||
def self.included(base) | ||
base.singleton_class.prepend(CommonMethods) | ||
end | ||
|
||
# Prepended instance methods for all patchers | ||
module CommonMethods | ||
attr_accessor \ | ||
:patch_error_result, | ||
:patch_successful | ||
|
||
def patch_name | ||
(self.class != Class && self.class != Module) ? self.class.name : name | ||
end | ||
|
||
def patched? | ||
patch_only_once.ran? | ||
end | ||
|
||
def patch | ||
return unless defined?(super) | ||
|
||
patch_only_once.run do | ||
super.tap do | ||
@patch_successful = true | ||
end | ||
rescue => e | ||
on_patch_error(e) | ||
end | ||
end | ||
|
||
# Processes patching errors. This default implementation logs the error and reports relevant metrics. | ||
# @param e [Exception] | ||
def on_patch_error(e) | ||
Datadog.logger.error("Failed to apply #{patch_name} patch. Cause: #{e} Location: #{Array(e.backtrace).first}") | ||
Datadog::Core::Telemetry::Logger.report(e, description: "Failed to apply #{patch_name} patch") | ||
|
||
@patch_error_result = { | ||
type: e.class.name, | ||
message: e.message, | ||
line: Array(e.backtrace).first | ||
} | ||
end | ||
|
||
private | ||
|
||
def patch_only_once | ||
# NOTE: This is not thread-safe | ||
@patch_only_once ||= Datadog::Core::Utils::OnlyOnce.new | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains 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 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 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 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 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 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 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 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 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 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,33 @@ | ||
module Datadog | ||
module CI | ||
module Contrib | ||
module Patcher | ||
def self.included: (untyped base) -> untyped | ||
|
||
module CommonMethods | ||
attr_accessor patch_error_result: untyped | ||
|
||
attr_accessor patch_successful: untyped | ||
|
||
def patch_name: () -> String? | ||
|
||
def name: () -> String | ||
|
||
def patched?: () -> bool | ||
|
||
def patch: () -> void | ||
|
||
def on_patch_error: (untyped e) -> untyped | ||
|
||
def default_tags: () -> untyped | ||
|
||
private | ||
|
||
def patch_only_once: () -> untyped | ||
|
||
@patch_only_once: Datadog::Core::Utils::OnlyOnce | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains 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 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 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 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 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,15 @@ | ||
module Datadog | ||
module Core | ||
module Telemetry | ||
module Logger | ||
def self.report: (Exception exception, ?level: Symbol, ?description: String?) -> void | ||
|
||
def self.error: (String description) -> void | ||
|
||
private | ||
|
||
def self.instance: () -> Datadog::Core::Telemetry::Component? | ||
end | ||
end | ||
end | ||
end |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know that it might be cumbersome to fill in, but maybe we can shape it a bit? Like if it's Array, we can state it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hopefully, while building auto instrumentation feature I will have a chance to rethink all of it and remove this all. Generally, all this stuff was created for APM use case and most of it isn't required for this more focused library and narrower use case.