Class: Rack::Insight::Instrumentation::Setup

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/insight/instrumentation/setup.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Setup

Returns a new instance of Setup.



3
4
5
# File 'lib/rack/insight/instrumentation/setup.rb', line 3

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



25
26
27
28
29
30
# File 'lib/rack/insight/instrumentation/setup.rb', line 25

def call(env)
  setup(env)
  status, headers, body = @app.call(env)
  teardown(env, status, headers, body)
  return [status, headers, body]
end

#setup(env) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'lib/rack/insight/instrumentation/setup.rb', line 7

def setup(env)
  instrument = Instrument.new

  PackageDefinition.start
  instrument.start(env)

  env["rack-insight.instrument"] = instrument
  Thread::current["rack-insight.instrument"] = instrument
end

#teardown(env, status, headers, body) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/rack/insight/instrumentation/setup.rb', line 17

def teardown(env, status, headers, body)
  instrument, env["rack-insight.instrument"] = env["rack-insight.instrument"], nil
  instrument.finish(env, status, headers, body)
  Thread::current["rack-insight.instrument"] = nil

  env["rack-insight.duration"] = instrument.duration
end