Skip to content

Commit 1486ed2

Browse files
committed
Add tracing around Client#make_response.
1 parent e0da7ab commit 1486ed2

File tree

1 file changed

+38
-28
lines changed

1 file changed

+38
-28
lines changed

lib/async/http/client.rb

Lines changed: 38 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def call(request)
101101
# As we cache pool, it's possible these pool go bad (e.g. closed by remote host). In this case, we need to try again. It's up to the caller to impose a timeout on this. If this is the last attempt, we force a new connection.
102102
connection = @pool.acquire
103103

104-
response = make_response(request, connection)
104+
response = make_response(request, connection, attempt)
105105

106106
# This signals that the ensure block below should not try to release the connection, because it's bound into the response which will be returned:
107107
connection = nil
@@ -140,6 +140,36 @@ def inspect
140140
"#<#{self.class} authority=#{@authority.inspect}>"
141141
end
142142

143+
protected
144+
145+
def make_response(request, connection, attempt)
146+
response = request.call(connection)
147+
148+
response.pool = @pool
149+
150+
return response
151+
end
152+
153+
def assign_default_tags(tags)
154+
tags[:endpoint] = @endpoint.to_s
155+
tags[:protocol] = @protocol.to_s
156+
end
157+
158+
def make_pool(**options)
159+
if connection_limit = options.delete(:connection_limit)
160+
warn "The connection_limit: option is deprecated, please use limit: instead.", uplevel: 2
161+
options[:limit] = connection_limit
162+
end
163+
164+
self.assign_default_tags(options[:tags] ||= {})
165+
166+
Async::Pool::Controller.wrap(**options) do
167+
Console.logger.debug(self) {"Making connection to #{@endpoint.inspect}"}
168+
169+
@protocol.client(@endpoint.connect)
170+
end
171+
end
172+
143173
Traces::Provider(self) do
144174
def call(request)
145175
attributes = {
@@ -178,35 +208,15 @@ def call(request)
178208
end
179209
end
180210
end
181-
end
182-
183-
protected
184-
185-
def make_response(request, connection)
186-
response = request.call(connection)
187-
188-
response.pool = @pool
189211

190-
return response
191-
end
192-
193-
def assign_default_tags(tags)
194-
tags[:endpoint] = @endpoint.to_s
195-
tags[:protocol] = @protocol.to_s
196-
end
197-
198-
def make_pool(**options)
199-
if connection_limit = options.delete(:connection_limit)
200-
warn "The connection_limit: option is deprecated, please use limit: instead.", uplevel: 2
201-
options[:limit] = connection_limit
202-
end
203-
204-
self.assign_default_tags(options[:tags] ||= {})
205-
206-
Async::Pool::Controller.wrap(**options) do
207-
Console.logger.debug(self) {"Making connection to #{@endpoint.inspect}"}
212+
def make_response(request, connection, attempt)
213+
attributes = {
214+
attempt: attempt,
215+
}
208216

209-
@protocol.client(@endpoint.connect)
217+
Traces.trace("async.http.client.make_response", attributes: attributes) do
218+
super
219+
end
210220
end
211221
end
212222
end

0 commit comments

Comments
 (0)