Class: NewRelic::Rack::AgentHooks

Inherits:
Object
  • Object
show all
Defined in:
lib/new_relic/rack/agent_hooks.rb

Constant Summary collapse

FIRED_FORMATS =
{
  :before_call => "newrelic.agent_hooks_before_fired",
  :after_call  => "newrelic.agent_hooks_after_fired"
}

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) ⇒ AgentHooks

Returns a new instance of AgentHooks.



9
10
11
# File 'lib/new_relic/rack/agent_hooks.rb', line 9

def initialize(app, options = {})
  @app = app
end

Instance Method Details

#call(env) ⇒ Object

method required by Rack interface

status, headers, response


20
21
22
23
24
25
# File 'lib/new_relic/rack/agent_hooks.rb', line 20

def call(env)
  notify(:before_call, env)
  result = @app.call(env)
  notify(:after_call, env, result)
  result
end

#eventsObject



33
34
35
# File 'lib/new_relic/rack/agent_hooks.rb', line 33

def events
  NewRelic::Agent.instance.events
end

#notify(event, env, *args) ⇒ Object



27
28
29
30
31
# File 'lib/new_relic/rack/agent_hooks.rb', line 27

def notify(event, env, *args)
  key = FIRED_FORMATS[event]
  events.notify(event, *([env] + args)) unless env[key]
  env[key] = true
end