Attributes
| handshake_time | [RW] |
when not nil, it means this request was sent to a non-open connection, and contains how much time it took the connection to connect. |
| init_time | [RW] |
time at which a request started being buffered for sending. |
Public Class methods
new(*)
intercepts request initialization to inject the tracing logic.
[show source]
# File lib/httpx/plugins/tracing.rb 74 def initialize(*) 75 super 76 77 @init_time = @handshake_time = nil 78 79 tracer = @options.tracer 80 81 return unless tracer && tracer.enabled?(self) 82 83 on(:idle) do 84 tracer.reset(self) 85 86 # request is reset when it's retried. 87 @init_time = @handshake_time = nil 88 end 89 on(:headers) do 90 # the usual request init time (when not including the connection handshake) 91 # should be the time the request is buffered the first time. 92 @init_time = ::Time.now.utc 93 @init_time -= @handshake_time if @handshake_time 94 95 tracer.start(self) 96 end 97 on(:response) { |response| tracer.finish(self, response) } 98 end
Public Instance methods
response=(*)
[show source]
# File lib/httpx/plugins/tracing.rb 100 def response=(*) 101 # There are situations where connection initialization fails. 102 # Example is the :ssrf_filter plugin, which raises an error on 103 # initialize if the host is an IP which matches against the known set. 104 # in such cases, we'll just set here right here. 105 @init_time ||= ::Time.now.utc 106 107 super 108 end