Class: Rack::Bug::SpeedTracerPanel::Middleware

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/bug/panels/speedtracer_panel.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Middleware

Returns a new instance of Middleware.



15
16
17
18
# File 'lib/rack/bug/panels/speedtracer_panel.rb', line 15

def initialize(app)
  @app = app
  @uuid = UUID.new
end

Instance Method Details

#call(env) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/rack/bug/panels/speedtracer_panel.rb', line 24

def call(env)
  if %r{^/__rack_bug__/} =~ env["REQUEST_URI"] 
    @app.call(env)
  else
    env['st.id'] = @uuid.generate

    tracer = SpeedTrace::Tracer.new(env['st.id'], 
                                    env['REQUEST_METHOD'], 
                                    env['REQUEST_URI'])
    env['st.tracer'] = tracer
    Thread::current['st.tracer'] = tracer

    status, headers, body = @app.call(env)

    env['st.tracer'].finish
    database[env['st.id']] = env['st.tracer']
    headers['X-TraceUrl'] = '/speedtracer?id=' + env['st.id']
    return [status, headers, body]
  end
end

#databaseObject



20
21
22
# File 'lib/rack/bug/panels/speedtracer_panel.rb', line 20

def database
  SpeedTracerPanel.database
end