Sha256: b2a85e5659a2627f587f3ebe018948efb2feeed05ac23d3fb3b8de8bdeaafc52

Contents?: true

Size: 896 Bytes

Versions: 8

Compression:

Stored size: 896 Bytes

Contents

# encoding: utf-8
# This file is distributed under New Relic's license terms.
# See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.

require 'new_relic/agent/event_listener'

module NewRelic::Rack
  class AgentHooks
    def initialize(app, options = {})
      @app = app
    end

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

    # method required by Rack interface
    # [status, headers, response]
    def call(env)
      notify(:before_call, env)
      result = @app.call(env)
      notify(:after_call, env, result)
      result
    end

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

    def events
      NewRelic::Agent.instance.events
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
newrelic_rpm-3.6.5.130 lib/new_relic/rack/agent_hooks.rb
newrelic_rpm-3.6.4.122 lib/new_relic/rack/agent_hooks.rb
newrelic_rpm-3.6.4.113.beta lib/new_relic/rack/agent_hooks.rb
newrelic_rpm-3.6.3.111 lib/new_relic/rack/agent_hooks.rb
newrelic_rpm-3.6.3.106 lib/new_relic/rack/agent_hooks.rb
newrelic_rpm-3.6.3.105.beta lib/new_relic/rack/agent_hooks.rb
newrelic_rpm-3.6.3.104 lib/new_relic/rack/agent_hooks.rb
newrelic_rpm-3.6.3.103.beta lib/new_relic/rack/agent_hooks.rb