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.



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

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.



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

def parent
  @parent
end

#queue_startObject (readonly)

Returns the value of attribute queue_start.



123
124
125
# File 'lib/new_relic/agent/instrumentation/action_controller_subscriber.rb', line 123

def queue_start
  @queue_start
end

#scopeObject

Returns the value of attribute scope.



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

def scope
  @scope
end

Instance Method Details

#_is_filtered?(key) ⇒ Boolean

FIXME: shamelessly ripped from ControllerInstrumentation

Returns:

  • (Boolean)


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

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)


164
165
166
# File 'lib/new_relic/agent/instrumentation/action_controller_subscriber.rb', line 164

def apdex_ignored?
  _is_filtered?('ignore_apdex')
end

#enduser_ignored?Boolean

Returns:

  • (Boolean)


168
169
170
# File 'lib/new_relic/agent/instrumentation/action_controller_subscriber.rb', line 168

def enduser_ignored?
  _is_filtered?('ignore_enduser')
end

#exception_encountered?Boolean

Returns:

  • (Boolean)


172
173
174
# File 'lib/new_relic/agent/instrumentation/action_controller_subscriber.rb', line 172

def exception_encountered?
  payload[:exception]
end

#finalize_metric_name!Object



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

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)


160
161
162
# File 'lib/new_relic/agent/instrumentation/action_controller_subscriber.rb', line 160

def ignored?
  _is_filtered?('do_not_trace')
end

#metric_actionObject



156
157
158
# File 'lib/new_relic/agent/instrumentation/action_controller_subscriber.rb', line 156

def metric_action
  payload[:action]
end

#metric_nameObject



136
137
138
# File 'lib/new_relic/agent/instrumentation/action_controller_subscriber.rb', line 136

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

#metric_pathObject



152
153
154
# File 'lib/new_relic/agent/instrumentation/action_controller_subscriber.rb', line 152

def metric_path
  @controller_class.controller_path
end

#to_sObject



193
194
195
# File 'lib/new_relic/agent/instrumentation/action_controller_subscriber.rb', line 193

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