Class: NewRelic::Agent::Instrumentation::ControllerEvent

Inherits:
Event
  • Object
show all
Defined in:
lib/new_relic/agent/instrumentation/action_controller_subscriber.rb

Instance Attribute Summary collapse

Attributes inherited from Event

#children, #end, #name, #payload, #time, #transaction_id

Instance Method Summary collapse

Methods inherited from Event

#<<, #duration, #parent_of?

Constructor Details

#initialize(name, start, ending, transaction_id, payload) ⇒ ControllerEvent

Returns a new instance of ControllerEvent.



123
124
125
126
127
128
129
130
131
132
# File 'lib/new_relic/agent/instrumentation/action_controller_subscriber.rb', line 123

def initialize(name, start, ending, transaction_id, payload)
  super

  @controller_class = payload[:controller].split('::') \
    .inject(Object){|m,o| m.const_get(o)}

  if payload[:request] && payload[:request].respond_to?(:env)
    @queue_start = QueueTime.parse_frontend_timestamp(payload[:request].env, self.time)
  end
end

Instance Attribute Details

#parentObject

Returns the value of attribute parent.



120
121
122
# File 'lib/new_relic/agent/instrumentation/action_controller_subscriber.rb', line 120

def parent
  @parent
end

#queue_startObject (readonly)

Returns the value of attribute queue_start.



121
122
123
# File 'lib/new_relic/agent/instrumentation/action_controller_subscriber.rb', line 121

def queue_start
  @queue_start
end

#scopeObject

Returns the value of attribute scope.



120
121
122
# File 'lib/new_relic/agent/instrumentation/action_controller_subscriber.rb', line 120

def scope
  @scope
end

Instance Method Details

#_is_filtered?(key) ⇒ Boolean

FIXME: shamelessly ripped from ControllerInstrumentation

Returns:

  • (Boolean)


175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# File 'lib/new_relic/agent/instrumentation/action_controller_subscriber.rb', line 175

def _is_filtered?(key)
  if @controller_class.respond_to? :newrelic_read_attr
    ignore_actions = @controller_class.newrelic_read_attr(key)
  end

  case ignore_actions
  when nil; false
  when Hash
    only_actions = Array(ignore_actions[:only])
    except_actions = Array(ignore_actions[:except])
    only_actions.include?(metric_action.to_sym) || (except_actions.any? && !except_actions.include?(metric_action.to_sym))
  else
    true
  end
end

#apdex_ignored?Boolean

Returns:

  • (Boolean)


162
163
164
# File 'lib/new_relic/agent/instrumentation/action_controller_subscriber.rb', line 162

def apdex_ignored?
  _is_filtered?('ignore_apdex')
end

#enduser_ignored?Boolean

Returns:

  • (Boolean)


166
167
168
# File 'lib/new_relic/agent/instrumentation/action_controller_subscriber.rb', line 166

def enduser_ignored?
  _is_filtered?('ignore_enduser')
end

#exception_encountered?Boolean

Returns:

  • (Boolean)


170
171
172
# File 'lib/new_relic/agent/instrumentation/action_controller_subscriber.rb', line 170

def exception_encountered?
  payload[:exception]
end

#finalize_metric_name!Object



138
139
140
141
142
143
144
145
146
147
148
# File 'lib/new_relic/agent/instrumentation/action_controller_subscriber.rb', line 138

def finalize_metric_name!
  txn = NewRelic::Agent::Transaction.current

  # the event provides the default name but the transaction has the final say
  txn.name ||= metric_name

  # this applies the transaction name rules if not already applied
  txn.freeze_name
  @metric_name = txn.name
  return @metric_name
end

#ignored?Boolean

Returns:

  • (Boolean)


158
159
160
# File 'lib/new_relic/agent/instrumentation/action_controller_subscriber.rb', line 158

def ignored?
  _is_filtered?('do_not_trace')
end

#metric_actionObject



154
155
156
# File 'lib/new_relic/agent/instrumentation/action_controller_subscriber.rb', line 154

def metric_action
  payload[:action]
end

#metric_nameObject



134
135
136
# File 'lib/new_relic/agent/instrumentation/action_controller_subscriber.rb', line 134

def metric_name
  @metric_name || "Controller/#{metric_path}/#{metric_action}"
end

#metric_pathObject



150
151
152
# File 'lib/new_relic/agent/instrumentation/action_controller_subscriber.rb', line 150

def metric_path
  @controller_class.controller_path
end

#to_sObject



191
192
193
# File 'lib/new_relic/agent/instrumentation/action_controller_subscriber.rb', line 191

def to_s
  "#<NewRelic::Agent::Instrumentation::ControllerEvent:#{object_id} name: \"#{name}\" id: #{transaction_id} payload: #{payload}}>"
end