Module: Datadog::Contrib::ActionView::Patcher

Includes:
Patcher
Defined in:
lib/ddtrace/contrib/action_view/patcher.rb

Overview

Patcher enables patching of ActionView module.

Class Method Summary collapse

Methods included from Patcher

included

Class Method Details

.patchObject



21
22
23
24
25
26
27
28
29
# File 'lib/ddtrace/contrib/action_view/patcher.rb', line 21

def patch
  do_once(:action_view) do
    begin
      patch_renderer
    rescue StandardError => e
      Datadog::Tracer.log.error("Unable to apply Action View integration: #{e} Location: #{e.backtrace.first}")
    end
  end
end

.patch_rendererObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/ddtrace/contrib/action_view/patcher.rb', line 31

def patch_renderer
  do_once(:patch_renderer) do
    if defined?(::ActionView::TemplateRenderer) && defined?(::ActionView::PartialRenderer)
      if Integration.version < Gem::Version.new('6.0.0')
        ::ActionView::TemplateRenderer.send(:prepend, Instrumentation::TemplateRenderer::Rails31To5)
        ::ActionView::PartialRenderer.send(:prepend, Instrumentation::PartialRenderer::RailsLessThan6)
      else
        ::ActionView::TemplateRenderer.send(:prepend, Instrumentation::TemplateRenderer::Rails6Plus)
        ::ActionView::PartialRenderer.send(:prepend, Instrumentation::PartialRenderer::Rails6Plus)
      end
    elsif defined?(::ActionView::Rendering) && defined?(::ActionView::Partials::PartialRenderer)
      # NOTE: Rails < 3.1 compatibility: different classes are used
      ::ActionView::Rendering.send(:prepend, Instrumentation::TemplateRenderer::Rails30)
      ::ActionView::Partials::PartialRenderer.send(:prepend, Instrumentation::PartialRenderer::RailsLessThan6)
    else
      Datadog::Tracer.log.debug('Expected Template/Partial classes not found; template rendering disabled')
    end
  end
end

.patched?Boolean

Returns:

  • (Boolean)


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

def patched?
  done?(:action_view)
end