-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #252 from DataDog/anmarchenko/decouple_patcher_fro…
…m_tracing [SDTEST-1129] Internal: decouple patcher from tracing, update ruby 3.4 compatibility
- Loading branch information
Showing
22 changed files
with
142 additions
and
39 deletions.
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
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
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 |