lib/async/http/client.rb in async-http-0.56.5 vs lib/async/http/client.rb in async-http-0.56.6

- old
+ new

@@ -26,10 +26,12 @@ require 'async/pool/controller' require 'protocol/http/body/completable' require 'protocol/http/methods' +require 'traces/provider' + require_relative 'protocol' module Async module HTTP DEFAULT_RETRIES = 3 @@ -132,9 +134,49 @@ else raise end ensure @pool.release(connection) if connection + end + end + + def inspect + "#<#{self.class} authority=#{@authority.inspect}>" + end + + Traces::Provider(self) do + def call(request) + attributes = { + 'http.method': request.method, + 'http.authority': request.authority || self.authority, + 'http.scheme': request.scheme || self.scheme, + 'http.path': request.path, + } + + if protocol = request.protocol + attributes['http.protocol'] = protocol + end + + if length = request.body&.length + attributes['http.request.length'] = length + end + + trace('async.http.client.call', attributes: attributes) do |span| + if context = trace_context(span) + request.headers['traceparent'] = context.to_s + # request.headers['tracestate'] = context.state + end + + super.tap do |response| + if status = response&.status + span['http.status_code'] = status + end + + if length = response.body&.length + span['http.response.length'] = length + end + end + end end end protected