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

Extended by:
DispatcherInstrumentation
Included in:
DispatcherInstrumentation
Defined in:
lib/new_relic/agent/instrumentation/dispatcher_instrumentation.rb

Defined Under Namespace

Modules: BusyCalculator

Instance Method Summary collapse

Instance Method Details

#dispatch_newrelic(*args) ⇒ Object

Used only when no before/after callbacks are available with the dispatcher, such as Rails before 2.0



47
48
49
50
51
52
53
54
# File 'lib/new_relic/agent/instrumentation/dispatcher_instrumentation.rb', line 47

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

#newrelic_dispatcher_finishObject



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

def newrelic_dispatcher_finish
  #puts @env.to_a.map{|k,v| "#{'%32s' % k}: #{v.inspect[0..64]}"}.join("\n")
  dispatcher_end_time = Time.now.to_f
  NewRelic::Agent.agent.end_transaction
  NewRelic::Agent::Instrumentation::DispatcherInstrumentation::BusyCalculator.dispatcher_finish dispatcher_end_time
  unless Thread.current[:newrelic_ignore_controller]
    elapsed_time = dispatcher_end_time - Thread.current[:newrelic_dispatcher_start]
    # Store the response header
    response_code = newrelic_response_code
    if response_code
      NewRelic::Agent.agent.stats_engine.get_stats_no_scope("HTTP/Response/#{response_code}").trace_call(elapsed_time)
    end
    # Store the response time
    dispatch_stat.trace_call(elapsed_time)
    NewRelic::Agent.instance.histogram.process(elapsed_time)
  end
end

#newrelic_dispatcher_startObject



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

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
  newrelic_dispatcher_start_time = Time.now.to_f
  Thread.current[:newrelic_dispatcher_start] = newrelic_dispatcher_start_time
  NewRelic::Agent::Instrumentation::DispatcherInstrumentation::BusyCalculator.dispatcher_start newrelic_dispatcher_start_time
  # 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]
  mongrel_queue_stat.trace_call(newrelic_dispatcher_start_time - mongrel_start.to_f) if mongrel_start
  NewRelic::Agent.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[:newrelic_ignore_controller] = nil
end

#newrelic_response_codeObject

Should be implemented in the dispatcher class



43
# File 'lib/new_relic/agent/instrumentation/dispatcher_instrumentation.rb', line 43

def newrelic_response_code; end