class HTTPClient private class Session def create_socket_with_logging(site) HttpEventLogger::Event::Connection.new(site.host, site.port) create_socket_without_logging(site) end alias_method_chain :create_socket, :logging end def do_get_block_with_logging(req, proxy, conn, &block) request_event = create_request_event(req) retryable_response_error = nil time_taken_in_seconds = ::Benchmark.realtime do begin do_get_block_without_logging(req, proxy, conn, &block) rescue RetryableResponse => exc retryable_response_error = exc end end res = conn.pop create_response_event(request_event, res, time_taken_in_seconds) conn.push(res) raise retryable_response_error unless retryable_response_error.nil? end alias_method_chain :do_get_block, :logging def create_request_event(req) HttpEventLogger::Event::Request.new( method: req.header.request_method, uri: req.header.request_uri, headers: req.headers, body: req.body ) end def create_response_event(request_event, res, time_taken_in_seconds) HttpEventLogger::Event::Response.new( request: request_event, time_taken_in_seconds: time_taken_in_seconds, status: res.status_code, headers: response_headers_from(res), body: res.body ) end def response_headers_from(res) res.header.all.reduce({}) do |result, header| result[header[0]] = header[1] result end end end if defined?(::HTTPClient)