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

Instance Method Summary collapse

Instance Attribute Details

#patch_error_resultObject

Returns the value of attribute patch_error_result.



22
23
24
# File 'lib/datadog/tracing/contrib/patcher.rb', line 22

def patch_error_result
  @patch_error_result
end

Instance Method Details

#default_tagsObject



72
73
74
75
76
77
# File 'lib/datadog/tracing/contrib/patcher.rb', line 72

def default_tags
  ["patcher:#{patch_name}"].tap do |tags|
    tags << "target_version:#{target_version}" if respond_to?(:target_version) && !target_version.nil?
    super.each { |t| tags << t } if defined?(super)
  end
end

#on_patch_error(e) ⇒ Object

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

Parameters:

  • e (Exception)


55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/datadog/tracing/contrib/patcher.rb', line 55

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
  }

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

  Datadog.health_metrics.error_instrumentation_patch(1, tags: tags)
end

#patchObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/datadog/tracing/contrib/patcher.rb', line 37

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)
        @patch_successful = true
      end
    rescue StandardError => e
      on_patch_error(e)
    end
  end
end

#patch_nameObject



29
30
31
# File 'lib/datadog/tracing/contrib/patcher.rb', line 29

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

#patch_successfulObject



25
26
27
# File 'lib/datadog/tracing/contrib/patcher.rb', line 25

def patch_successful
  !!@patch_successful
end

#patched?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/datadog/tracing/contrib/patcher.rb', line 33

def patched?
  patch_only_once.ran?
end