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.



118
119
120
121
122
123
124
125
126
127
# File 'lib/new_relic/agent/instrumentation/action_controller_subscriber.rb', line 118

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.



115
116
117
# File 'lib/new_relic/agent/instrumentation/action_controller_subscriber.rb', line 115

def parent
  @parent
end

#queue_startObject (readonly)

Returns the value of attribute queue_start.



116
117
118
# File 'lib/new_relic/agent/instrumentation/action_controller_subscriber.rb', line 116

def queue_start
  @queue_start
end

#scopeObject

Returns the value of attribute scope.



115
116
117
# File 'lib/new_relic/agent/instrumentation/action_controller_subscriber.rb', line 115

def scope
  @scope
end

Instance Method Details

#_is_filtered?(key) ⇒ Boolean

FIXME: shamelessly ripped from ControllerInstrumentation

Returns:

  • (Boolean)


170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# File 'lib/new_relic/agent/instrumentation/action_controller_subscriber.rb', line 170

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)


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

def apdex_ignored?
  _is_filtered?('ignore_apdex')
end

#enduser_ignored?Boolean

Returns:

  • (Boolean)


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

def enduser_ignored?
  _is_filtered?('ignore_enduser')
end

#exception_encountered?Boolean

Returns:

  • (Boolean)


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

def exception_encountered?
  payload[:exception]
end

#finalize_metric_name!Object



133
134
135
136
137
138
139
140
141
142
143
# File 'lib/new_relic/agent/instrumentation/action_controller_subscriber.rb', line 133

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)


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

def ignored?
  _is_filtered?('do_not_trace')
end

#metric_actionObject



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

def metric_action
  payload[:action]
end

#metric_nameObject



129
130
131
# File 'lib/new_relic/agent/instrumentation/action_controller_subscriber.rb', line 129

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

#metric_pathObject



145
146
147
# File 'lib/new_relic/agent/instrumentation/action_controller_subscriber.rb', line 145

def metric_path
  @controller_class.controller_path
end

#to_sObject



186
187
188
# File 'lib/new_relic/agent/instrumentation/action_controller_subscriber.rb', line 186

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