Class: ScoutApm::Instruments::ActionView
- Inherits:
-
Object
- Object
- ScoutApm::Instruments::ActionView
show all
- Defined in:
- lib/scout_apm/instruments/action_view.rb
Defined Under Namespace
Modules: ActionViewCollectionRendererInstruments, ActionViewPartialRendererInstruments, ActionViewTemplateRendererInstruments
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(context) ⇒ ActionView
Returns a new instance of ActionView.
15
16
17
18
|
# File 'lib/scout_apm/instruments/action_view.rb', line 15
def initialize(context)
@context = context
@installed = false
end
|
Instance Attribute Details
#context ⇒ Object
Returns the value of attribute context.
13
14
15
|
# File 'lib/scout_apm/instruments/action_view.rb', line 13
def context
@context
end
|
Instance Method Details
#install(prepend:) ⇒ Object
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/scout_apm/instruments/action_view.rb', line 32
def install(prepend:)
return unless defined?(::ActionView) && defined?(::ActionView::PartialRenderer)
if prependable?
install_using_prepend
else
install_using_tracer
end
@installed = true
end
|
#install_using_prepend ⇒ Object
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/scout_apm/instruments/action_view.rb', line 69
def install_using_prepend
logger.info "Instrumenting ActionView::PartialRenderer"
::ActionView::PartialRenderer.prepend(ActionViewPartialRendererInstruments)
logger.info "Instrumenting ActionView::TemplateRenderer"
::ActionView::TemplateRenderer.prepend(ActionViewTemplateRendererInstruments)
if defined?(::ActionView::CollectionRenderer)
logger.info "Instrumenting ActionView::CollectionRenderer"
::ActionView::CollectionRenderer.prepend(ActionViewCollectionRendererInstruments)
end
end
|
#install_using_tracer ⇒ Object
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/scout_apm/instruments/action_view.rb', line 43
def install_using_tracer
logger.info "Instrumenting ActionView::PartialRenderer"
::ActionView::PartialRenderer.class_eval do
include ScoutApm::Tracer
instrument_method :render_partial,
:type => "View",
:name => '#{@template.virtual_path rescue "Unknown Partial"}/Rendering',
:scope => true
instrument_method :collection_with_template,
:type => "View",
:name => '#{@template.virtual_path rescue "Unknown Collection"}/Rendering',
:scope => true
end
logger.info "Instrumenting ActionView::TemplateRenderer"
::ActionView::TemplateRenderer.class_eval do
include ScoutApm::Tracer
instrument_method :render_template,
:type => "View",
:name => '#{args[0].virtual_path rescue "Unknown"}/Rendering',
:scope => true
end
end
|
#installed? ⇒ Boolean
24
25
26
|
# File 'lib/scout_apm/instruments/action_view.rb', line 24
def installed?
@installed
end
|
#logger ⇒ Object
20
21
22
|
# File 'lib/scout_apm/instruments/action_view.rb', line 20
def logger
context.logger
end
|
#prependable? ⇒ Boolean
28
29
30
|
# File 'lib/scout_apm/instruments/action_view.rb', line 28
def prependable?
context.environment.supports_module_prepend?
end
|