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)


40
41
42
43
44
45
46
47
48
49
# File 'lib/ddtrace/contrib/patcher.rb', line 40

def on_patch_error(e)
  # Log the error
  Datadog.logger.error("Failed to apply #{patch_name} patch. Cause: #{e} Location: #{Array(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



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/ddtrace/contrib/patcher.rb', line 23

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: default_tags)
      end
    rescue StandardError => e
      on_patch_error(e)
    end
  end
end

#patch_nameObject



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

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

#patched?Boolean

Returns:

  • (Boolean)


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

def patched?
  patch_only_once.ran?
end