Skip to content

Commit

Permalink
Add support for instrumentation tags.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Oct 13, 2024
1 parent 0eb1c3d commit 18d4a91
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
7 changes: 4 additions & 3 deletions async-http.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ Gem::Specification.new do |spec|
spec.required_ruby_version = ">= 3.1"

spec.add_dependency "async", ">= 2.10.2"
spec.add_dependency "async-pool", "~> 0.7"
spec.add_dependency "io-endpoint", "~> 0.11"
spec.add_dependency "async-pool", "~> 0.9"
spec.add_dependency "io-endpoint", "~> 0.14"
spec.add_dependency "io-stream", "~> 0.4"
spec.add_dependency "protocol-http", "~> 0.37"
spec.add_dependency "protocol-http1", "~> 0.27"
spec.add_dependency "protocol-http2", "~> 0.19"
spec.add_dependency "traces", ">= 0.10"
spec.add_dependency "traces", "~> 0.10"
spec.add_dependency "metrics", "~> 0.12"
end
21 changes: 16 additions & 5 deletions lib/async/http/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
module Async
module HTTP
DEFAULT_RETRIES = 3
DEFAULT_CONNECTION_LIMIT = nil

class Client < ::Protocol::HTTP::Methods
# Provides a robust interface to a server.
Expand All @@ -30,12 +29,12 @@ class Client < ::Protocol::HTTP::Methods
# @param protocol [Protocol::HTTP1 | Protocol::HTTP2 | Protocol::HTTPS] the protocol to use.
# @param scheme [String] The default scheme to set to requests.
# @param authority [String] The default authority to set to requests.
def initialize(endpoint, protocol: endpoint.protocol, scheme: endpoint.scheme, authority: endpoint.authority, retries: DEFAULT_RETRIES, connection_limit: DEFAULT_CONNECTION_LIMIT)
def initialize(endpoint, protocol: endpoint.protocol, scheme: endpoint.scheme, authority: endpoint.authority, retries: DEFAULT_RETRIES, **options)
@endpoint = endpoint
@protocol = protocol

@retries = retries
@pool = make_pool(connection_limit)
@pool = make_pool(**options)

@scheme = scheme
@authority = authority
Expand Down Expand Up @@ -191,8 +190,20 @@ def make_response(request, connection)
return response
end

def make_pool(connection_limit)
Async::Pool::Controller.wrap(limit: connection_limit) do
def assign_default_tags(tags)
tags[:endpoint] = @endpoint.to_s
tags[:protocol] = @protocol.to_s
end

def make_pool(**options)
if connection_limit = options.delete(:connection_limit)
warn "The connection_limit: option is deprecated, please use limit: instead.", uplevel: 2
options[:limit] = connection_limit
end

self.assign_default_tags(options[:tags] ||= {})

Async::Pool::Controller.wrap(**options) do
Console.logger.debug(self) {"Making connection to #{@endpoint.inspect}"}

@protocol.client(@endpoint.connect)
Expand Down

0 comments on commit 18d4a91

Please sign in to comment.