Class: NewRelic::Agent::Instrumentation::ActionControllerSubscriber
Instance Method Summary
collapse
#event_stack, #pop_event, #push_event, subscribe, subscribed?
Constructor Details
Returns a new instance of ActionControllerSubscriber.
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/new_relic/agent/instrumentation/action_controller_subscriber.rb', line 10
def initialize
super
NewRelic::Agent.instance.events.subscribe(:before_call) do |env|
request = begin
require 'rack'
::Rack::Request.new(env)
rescue => e
Agent.logger.debug("Error creating Rack::Request object: #{e}")
nil
end
TransactionInfo.reset(request)
end
end
|
Instance Method Details
#filter(params) ⇒ Object
108
109
110
111
|
# File 'lib/new_relic/agent/instrumentation/action_controller_subscriber.rb', line 108
def filter(params)
filters = Rails.application.config.filter_parameters
ActionDispatch::Http::ParameterFilter.new(filters).filter(params)
end
|
#finish(name, id, payload) ⇒ Object
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/new_relic/agent/instrumentation/action_controller_subscriber.rb', line 39
def finish(name, id, payload)
event = pop_event(id)
event.payload.merge!(payload)
set_enduser_ignore if event.enduser_ignored?
if NewRelic::Agent.is_execution_traced? && !event.ignored?
event.finalize_metric_name!
record_queue_time(event)
record_metrics(event)
record_apdex(event)
record_instance_busy(event)
stop_transaction(event)
else
Agent.instance.pop_trace_execution_flag
end
end
|
#record_apdex(event) ⇒ Object
78
79
80
81
|
# File 'lib/new_relic/agent/instrumentation/action_controller_subscriber.rb', line 78
def record_apdex(event)
return if event.apdex_ignored?
Transaction.record_apdex(event.end, event.exception_encountered?)
end
|
#record_instance_busy(event) ⇒ Object
#record_metric_on_parent_transaction(metric, time) ⇒ Object
74
75
76
|
# File 'lib/new_relic/agent/instrumentation/action_controller_subscriber.rb', line 74
def record_metric_on_parent_transaction(metric, time)
NewRelic::Agent::Transaction.parent.stats_hash.record(metric, time)
end
|
#record_metrics(event) ⇒ Object
61
62
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/new_relic/agent/instrumentation/action_controller_subscriber.rb', line 61
def record_metrics(event)
controller_metric = MetricSpec.new(event.metric_name)
txn = Transaction.current
metrics = [ 'HttpDispatcher']
if txn.has_parent?
parent_metric = MetricSpec.new(event.metric_name, StatsEngine::MetricStats::SCOPE_PLACEHOLDER)
record_metric_on_parent_transaction(parent_metric, event.duration)
end
metrics << controller_metric.dup
Agent.instance.stats_engine.record_metrics(metrics, event.duration)
end
|
#record_queue_time(event) ⇒ Object
88
89
90
91
|
# File 'lib/new_relic/agent/instrumentation/action_controller_subscriber.rb', line 88
def record_queue_time(event)
return unless event.queue_start
QueueTime.record_frontend_metrics(event.queue_start, event.time)
end
|
#set_enduser_ignore ⇒ Object
57
58
59
|
# File 'lib/new_relic/agent/instrumentation/action_controller_subscriber.rb', line 57
def set_enduser_ignore
TransactionInfo.get.ignore_end_user = true
end
|
#start(name, id, payload) ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/new_relic/agent/instrumentation/action_controller_subscriber.rb', line 25
def start(name, id, payload)
payload[:request] = TransactionInfo.get.request
event = ControllerEvent.new(name, Time.now, nil, id, payload)
push_event(event)
if NewRelic::Agent.is_execution_traced? && !event.ignored?
start_transaction(event)
else
NewRelic::Agent.instance.push_trace_execution_flag(false)
end
end
|
#start_transaction(event) ⇒ Object
93
94
95
96
97
98
99
100
|
# File 'lib/new_relic/agent/instrumentation/action_controller_subscriber.rb', line 93
def start_transaction(event)
txn = Transaction.start(:controller,
:request => event.payload[:request],
:filtered_params => filter(event.payload[:params]))
txn.apdex_start = (event.queue_start || event.time)
event.scope = Agent.instance.stats_engine \
.push_scope(:action_controller, event.time)
end
|
#stop_transaction(event) ⇒ Object
102
103
104
105
106
|
# File 'lib/new_relic/agent/instrumentation/action_controller_subscriber.rb', line 102
def stop_transaction(event)
Agent.instance.stats_engine \
.pop_scope(event.scope, event.metric_name, event.end)
Transaction.stop
end
|