Class: Rester::Service::Middleware::RequestHandler

Inherits:
Base
  • Object
show all
Defined in:
lib/rester/service/middleware/request_handler.rb

Overview

Create a Request object for this thread, store the correlation ID, and perform the necessary logging. Cleanup the request once it’s complete.

Instance Attribute Summary

Attributes inherited from Base

#app, #options

Instance Method Summary collapse

Methods inherited from Base

#initialize, #service

Constructor Details

This class inherits a constructor from Rester::Service::Middleware::Base

Instance Method Details

#call(env) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/rester/service/middleware/request_handler.rb', line 7

def call(env)
  Rester.wrap_request do
    Rester.request = request = Rester::Service::Request.new(env)
    Rester.correlation_id = request.correlation_id
    Rester.request_info[:producer_name] = service.name
    Rester.request_info[:consumer_name] = request.consumer_name
    Rester.request_info[:path] = request.path_info
    Rester.request_info[:verb] = request.request_method

    service.logger.info('request received')

    start_time = Time.now.to_f
    super.tap { |response|
      elapsed_ms = (Time.now.to_f - start_time) * 1000
      response[1]["X-Rester-Producer-Name"] = service.name
      service.logger.info("responding with #{response[0]} after %0.3fms" %
        elapsed_ms)
    }
  end
end