Class: NewRelic::Starter::Rack

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

Overview

NewRelic::Starter::Rack is a Rack middleware that provides an endpoint to start the New Relic agent.

Instance Method Summary collapse

Constructor Details

#initialize(app, latch: Latch.new, path: nil) ⇒ NewRelic::Starter::Rack

Returns a new NewRelic::Starter::Rack which implements the Rack interface.

Parameters:

  • app (Object)

    the Rack application

  • latch (NewRelic::Starter::Latch) (defaults to: Latch.new)

    the latch object

  • path (String) (defaults to: nil)

    the path of the endpoint to start the New Relic agent



17
18
19
20
21
22
# File 'lib/new_relic/starter/rack.rb', line 17

def initialize(app, latch: Latch.new, path: nil)
  @app = app
  @latch = latch
  @path = path || '/_new_relic/start'
  @starter = Starter.new(latch)
end

Instance Method Details

#call(env) ⇒ Array

Opens a latch and start the New Relic agent if the path of the request matches with the path of the endpoint.

When the path doesn’t match, if a latch is opened, the agent is started before calling the next application.

Parameters:

  • env (Hash)

    the Rack environment

Returns:

  • (Array)

    the Rack response



32
33
34
35
36
37
38
39
# File 'lib/new_relic/starter/rack.rb', line 32

def call(env)
  if env['PATH_INFO'] == @path
    handle
  else
    @starter.start
    @app.call(env)
  end
end