-
Notifications
You must be signed in to change notification settings - Fork 12
Request time
José Bonnet edited this page Jul 9, 2019
·
1 revision
This wiki page explains the design of the feature that returns in an HTTP header the time every request took to be answered.
Every HTTP request goes through the platform's API Gateway, which alows the counting of the time taken by each request.
This is achieved by using an Instrumentation
(ruby) rack middleware that simply collects the time when the request entered the middleware, calculating the difference when the request returns, and storing it in the X-Timing
HTTP header of the response. In code (with irrelevant code ommited), we have:
...
def call(env)
began_at = Time.now
status, headers, body = @app.call env
headers['X-Timing'] = (Time.now - began_at).to_f.to_s
[status, headers, body]
end
...