Module: NewRelic::Agent::Instrumentation::DispatcherInstrumentation

Defined in:
lib/new_relic/agent/instrumentation/dispatcher_instrumentation.rb

Defined Under Namespace

Modules: BusyCalculator

Constant Summary collapse

@@newrelic_agent =
NewRelic::Agent.agent
@@newrelic_rails_dispatch_stat =
@@newrelic_agent.stats_engine.get_stats 'Rails/HTTP Dispatch'
@@newrelic_mongrel_queue_stat =
@@newrelic_agent.stats_engine.get_stats('WebFrontend/Mongrel/Average Queue Time')

Instance Method Summary collapse

Instance Method Details

#dispatch_newrelic(*args) ⇒ Object



41
42
43
44
45
46
47
48
# File 'lib/new_relic/agent/instrumentation/dispatcher_instrumentation.rb', line 41

def dispatch_newrelic(*args)
  newrelic_dispatcher_start
  begin
    dispatch_without_newrelic(*args)
  ensure
    newrelic_dispatcher_finish
  end
end

#newrelic_dispatcher_finishObject



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/new_relic/agent/instrumentation/dispatcher_instrumentation.rb', line 28

def newrelic_dispatcher_finish
  t0 = Thread.current[:newrelic_t0]
  if t0.nil?
    NewRelic::Config.instance.log.warn "Dispatcher finish called twice!\n#{caller.join("\n   ")}" 
    return
  end
  t1 = Time.now.to_f
  @@newrelic_agent.end_transaction
  @@newrelic_rails_dispatch_stat.trace_call(t1 - t0) unless Thread.current[:controller_ignored]
  NewRelic::Agent::Instrumentation::DispatcherInstrumentation::BusyCalculator.dispatcher_finish t1    
  Thread.current[:newrelic_t0] = nil
end

#newrelic_dispatcher_startObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/new_relic/agent/instrumentation/dispatcher_instrumentation.rb', line 10

def newrelic_dispatcher_start
  # Put the current time on the thread.  Can't put in @ivar because this could
  # be a class or instance context
  t0 = Time.now.to_f
  NewRelic::Config.instance.log.warn "Recursive entry into dispatcher_start!\n#{caller.join("\n   ")}" if Thread.current[:newrelic_t0]
  Thread.current[:newrelic_t0] = t0
  NewRelic::Agent::Instrumentation::DispatcherInstrumentation::BusyCalculator.dispatcher_start t0
  # capture the time spent in the mongrel queue, if running in mongrel.  This is the 
  # current time less the timestamp placed in 'started_on' by mongrel. 
  mongrel_start = Thread.current[:started_on]
  @@newrelic_mongrel_queue_stat.trace_call(t0 - mongrel_start.to_f) if mongrel_start
  @@newrelic_agent.start_transaction
  
  # Reset the flag indicating the controller action should be ignored.
  # It may be set by the action to either true or false or left nil meaning false
  Thread.current[:controller_ignored] = nil
end