module Datadog::Contrib::Patcher::CommonMethods

Prepended instance methods for all patchers

Public Instance Methods

on_patch_error(e) click to toggle source

Processes patching errors. This default implementation logs the error and reports relevant metrics. @param e [Exception]

# File lib/ddtrace/contrib/patcher.rb, line 41
def on_patch_error(e)
  # Log the error
  Datadog.logger.error("Failed to apply #{patch_name} patch. Cause: #{e} Location: #{e.backtrace.first}")

  # Emit a metric
  tags = default_tags
  tags << "error:#{e.class.name}"

  Datadog.health_metrics.error_instrumentation_patch(1, tags: tags)
end
patch() click to toggle source
Calls superclass method
# File lib/ddtrace/contrib/patcher.rb, line 24
def patch
  return unless defined?(super)

  do_once(:patch) do
    begin
      super.tap do
        # Emit a metric
        Datadog.health_metrics.instrumentation_patched(1, tags: default_tags)
      end
    rescue StandardError => e
      on_patch_error(e)
    end
  end
end
patch_name() click to toggle source
# File lib/ddtrace/contrib/patcher.rb, line 16
def patch_name
  self.class != Class && self.class != Module ? self.class.name : name
end
patched?() click to toggle source
# File lib/ddtrace/contrib/patcher.rb, line 20
def patched?
  done?(:patch)
end

Private Instance Methods

default_tags() click to toggle source
# File lib/ddtrace/contrib/patcher.rb, line 54
def default_tags
  ["patcher:#{patch_name}"].tap do |tags|
    tags << "target_version:#{target_version}" if respond_to?(:target_version) && !target_version.nil?
  end
end