Module: HTTPX::Plugins::Tracing::ConnectionMethods

Defined in:
lib/httpx/plugins/tracing.rb,
sig/plugins/tracing.rbs

Overview

Connection mixin

Instance Method Summary collapse

Instance Method Details

#disconnect ⇒ Object



173
174
175
176
177
178
179
180
# File 'lib/httpx/plugins/tracing.rb', line 173

def disconnect
  prevstate = @state

  super.tap do |was_closed|
    # reset init time of connections abandoned while connecting.
    @init_time = nil if was_closed && connecting?(prevstate)
  end
end

#idling ⇒ Object



160
161
162
163
164
# File 'lib/httpx/plugins/tracing.rb', line 160

def idling
  super

  @init_time = nil
end

#initialize ⇒ Object



135
136
137
138
139
# File 'lib/httpx/plugins/tracing.rb', line 135

def initialize(*)
  super

  @init_time = nil
end

#send(request) ⇒ Object



141
142
143
144
145
146
147
# File 'lib/httpx/plugins/tracing.rb', line 141

def send(request)
  # requests may be rerouted to other connections (i.e. when coalescing), so only the first
  # connection the request is handed to marks it.
  request.enqueue_time ||= ::Time.now.utc

  super
end

#send_request_to_parser(request) ⇒ Object



149
150
151
152
153
154
155
156
157
158
# File 'lib/httpx/plugins/tracing.rb', line 149

def send_request_to_parser(request, *)
  if connecting? && @init_time
    # at this point, the connection has connected, but hasn't yet transitioned to :open,
    # so it's the time the requests which caused this connection to connect, are finally being
    # sent to the parser, so handshake time should factor into the span time.
    request.handshake_time ||= ::Time.now.utc - @init_time
  end

  super
end

#terminate ⇒ Object



166
167
168
169
170
171
# File 'lib/httpx/plugins/tracing.rb', line 166

def terminate
  super

  # ensure that connections which go back to the pool reset their init time.
  @init_time = nil
end