Class: Goliath::Rack::Tracer
- Inherits:
-
Object
- Object
- Goliath::Rack::Tracer
- Defined in:
- lib/goliath/rack/tracer.rb
Overview
Middleware to inject the tracer statistics into the response headers.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ Tracer
constructor
A new instance of Tracer.
- #post_process(env, status, headers, body) ⇒ Object
Constructor Details
#initialize(app) ⇒ Tracer
Returns a new instance of Tracer.
9 10 11 |
# File 'lib/goliath/rack/tracer.rb', line 9 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/goliath/rack/tracer.rb', line 13 def call(env) async_cb = env['async.callback'] env['async.callback'] = Proc.new do |status, headers, body| async_cb.call(post_process(env, status, headers, body)) env.logger.info env.trace_stats.collect{|s| s.join(':')}.join(', ') end status, headers, body = @app.call(env) post_process(env, status, headers, body) end |
#post_process(env, status, headers, body) ⇒ Object
25 26 27 28 |
# File 'lib/goliath/rack/tracer.rb', line 25 def post_process(env, status, headers, body) extra = { 'X-PostRank' => env.trace_stats.collect{|s| s.join(': ')}.join(', ')} [status, headers.merge(extra), body] end |