Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

show connection time in Net::HTTP requests #534

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions lib/patches/net_patches.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@

if defined?(Rack::MINI_PROFILER_PREPEND_NET_HTTP_PATCH)
module NetHTTPWithMiniProfiler
def connect()
if proxy? then
conn_addr = proxy_address
conn_port = proxy_port
else
conn_addr = conn_address
conn_port = port
end
Rack::MiniProfiler.step("Net::HTTP Connect #{conn_addr}:#{conn_port}") do
super
end
end
def request(request, *args, &block)
Rack::MiniProfiler.step("Net::HTTP #{request.method} #{request.path}") do
super
Expand All @@ -13,6 +25,20 @@ def request(request, *args, &block)
Net::HTTP.prepend(NetHTTPWithMiniProfiler)
else
Net::HTTP.class_eval do
def connect_with_mini_profiler()
if proxy? then
conn_addr = proxy_address
conn_port = proxy_port
else
conn_addr = conn_address
conn_port = port
end
Rack::MiniProfiler.step("Net::HTTP Connect #{conn_addr}:#{conn_port}") do
connect_without_mini_profiler()
end
end
alias connect_without_mini_profiler connect
alias connect connect_with_mini_profiler
def request_with_mini_profiler(*args, &block)
request = args[0]
Rack::MiniProfiler.step("Net::HTTP #{request.method} #{request.path}") do
Expand Down