Module: Datadog::Tracing::Contrib::Patcher::CommonMethods
- Defined in:
- lib/datadog/tracing/contrib/patcher.rb
Overview
Prepended instance methods for all patchers
Instance Attribute Summary collapse
-
#patch_error_result ⇒ Object
Returns the value of attribute patch_error_result.
-
#patch_successful ⇒ Object
Returns the value of attribute patch_successful.
Instance Method Summary collapse
- #default_tags ⇒ Object
-
#on_patch_error(e) ⇒ Object
Processes patching errors.
- #patch ⇒ Object
- #patch_name ⇒ Object
- #patched? ⇒ Boolean
Instance Attribute Details
#patch_error_result ⇒ Object
Returns the value of attribute patch_error_result.
20 21 22 |
# File 'lib/datadog/tracing/contrib/patcher.rb', line 20 def patch_error_result @patch_error_result end |
#patch_successful ⇒ Object
Returns the value of attribute patch_successful.
20 21 22 |
# File 'lib/datadog/tracing/contrib/patcher.rb', line 20 def patch_successful @patch_successful end |
Instance Method Details
#default_tags ⇒ Object
67 68 69 70 71 72 |
# File 'lib/datadog/tracing/contrib/patcher.rb', line 67 def ["patcher:#{patch_name}"].tap do || << "target_version:#{target_version}" if respond_to?(:target_version) && !target_version.nil? super.each { |t| << t } if defined?(super) end end |
#on_patch_error(e) ⇒ Object
Processes patching errors. This default implementation logs the error and reports relevant metrics.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/datadog/tracing/contrib/patcher.rb', line 50 def on_patch_error(e) # Log the error Datadog.logger.error("Failed to apply #{patch_name} patch. Cause: #{e} Location: #{Array(e.backtrace).first}") @patch_error_result = { type: e.class.name, message: e., line: Array(e.backtrace).first } # Emit a metric = << "error:#{e.class.name}" Datadog.health_metrics.error_instrumentation_patch(1, tags: ) end |
#patch ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/datadog/tracing/contrib/patcher.rb', line 32 def patch return unless defined?(super) patch_only_once.run do begin super.tap do # Emit a metric Datadog.health_metrics.instrumentation_patched(1, tags: ) @patch_successful = true end rescue StandardError => e on_patch_error(e) end end end |
#patch_name ⇒ Object
24 25 26 |
# File 'lib/datadog/tracing/contrib/patcher.rb', line 24 def patch_name self.class != Class && self.class != Module ? self.class.name : name end |
#patched? ⇒ Boolean
28 29 30 |
# File 'lib/datadog/tracing/contrib/patcher.rb', line 28 def patched? patch_only_once.ran? end |