Class: Goliath::Rack::Tracer
- Inherits:
-
Object
- Object
- Goliath::Rack::Tracer
- Includes:
- AsyncMiddleware
- 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, header_name = nil) ⇒ Tracer
constructor
A new instance of Tracer.
- #post_process(env, status, headers, body) ⇒ Object
Methods included from AsyncMiddleware
#final_response?, #hook_into_callback_chain
Methods included from Validator
Constructor Details
#initialize(app, header_name = nil) ⇒ Tracer
Returns a new instance of Tracer.
11 12 13 14 |
# File 'lib/goliath/rack/tracer.rb', line 11 def initialize(app, header_name=nil) super(app) @header_name = header_name || 'X-PostRank' end |
Instance Method Details
#call(env) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/goliath/rack/tracer.rb', line 16 def call(env) env.trace 'trace.start' shb = super(env) env.logger.info env.trace_stats.collect{|s| s.join(':')}.join(', ') shb end |
#post_process(env, status, headers, body) ⇒ Object
23 24 25 26 27 |
# File 'lib/goliath/rack/tracer.rb', line 23 def post_process(env, status, headers, body) extra = { @header_name => env.trace_stats.collect{|s| s.join(': ')}.join(', ')} env.logger.info env.trace_stats.collect{|s| s.join(':')}.join(', ') [status, headers.merge(extra), body] end |