class Datadog::Transport::HTTP::Builder
Builds new instances of Transport::HTTP::Client
Constants
- REGISTRY
Attributes
api_options[R]
apis[R]
default_adapter[R]
default_api[R]
default_headers[R]
Public Class Methods
new() { |self| ... }
click to toggle source
# File lib/ddtrace/transport/http/builder.rb, line 20 def initialize # Global settings @default_adapter = nil @default_headers = {} # Client settings @apis = API::Map.new @default_api = nil # API settings @api_options = {} yield(self) if block_given? end
Public Instance Methods
adapter(type, *args)
click to toggle source
# File lib/ddtrace/transport/http/builder.rb, line 35 def adapter(type, *args) @default_adapter = if type.is_a?(Symbol) registry_klass = REGISTRY.get(type) raise UnknownAdapterError, type if registry_klass.nil? registry_klass.new(*args) else type end end
api(key, spec, options = {})
click to toggle source
Adds a new API
to the client Valid options:
- :adapter - :default - :fallback - :headers
# File lib/ddtrace/transport/http/builder.rb, line 55 def api(key, spec, options = {}) options = options.dup # Copy spec into API map @apis[key] = spec # Apply as default API, if specified to do so. @default_api = key if options.delete(:default) || @default_api.nil? # Save all other settings for initialization (@api_options[key] ||= {}).merge!(options) end
default_api=(key)
click to toggle source
# File lib/ddtrace/transport/http/builder.rb, line 68 def default_api=(key) raise UnknownApiError, key unless @apis.key?(key) @default_api = key end
headers(values = {})
click to toggle source
# File lib/ddtrace/transport/http/builder.rb, line 45 def headers(values = {}) @default_headers.merge!(values) end
to_api_instances()
click to toggle source
# File lib/ddtrace/transport/http/builder.rb, line 80 def to_api_instances raise NoApisError if @apis.empty? @apis.inject(API::Map.new) do |instances, (key, spec)| instances.tap do api_options = @api_options[key].dup # Resolve the adapter to use for this API adapter = api_options.delete(:adapter) || @default_adapter raise NoAdapterForApiError, key if adapter.nil? # Resolve fallback and merge headers fallback = api_options.delete(:fallback) api_options[:headers] = @default_headers.merge((api_options[:headers] || {})) # Add API::Instance with all settings instances[key] = API::Instance.new( spec, adapter, api_options ) # Configure fallback, if provided. instances.with_fallbacks(key => fallback) unless fallback.nil? end end end
to_transport()
click to toggle source
# File lib/ddtrace/transport/http/builder.rb, line 73 def to_transport raise NoDefaultApiError if @default_api.nil? # DEV: Should not be specific to traces Transport::Traces::Transport.new(to_api_instances, @default_api) end