Module: Datadog::Contrib::Patcher::CommonMethods

Defined in:
lib/ddtrace/contrib/patcher.rb

Overview

Prepended instance methods for all patchers

Instance Method Summary collapse

Instance Method Details

#on_patch_error(e) ⇒ Object

Processes patching errors. This default implementation logs the error and reports relevant metrics.

Parameters:

  • e (Exception)


41
42
43
44
45
46
47
48
49
50
# 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

#patchObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# 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_nameObject



16
17
18
# File 'lib/ddtrace/contrib/patcher.rb', line 16

def patch_name
  self.class != Class && self.class != Module ? self.class.name : name
end

#patched?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/ddtrace/contrib/patcher.rb', line 20

def patched?
  done?(:patch)
end