Module: Datadog::Transport::HTTP

Defined in:
lib/ddtrace/transport/http.rb,
lib/ddtrace/transport/http/api.rb,
lib/ddtrace/transport/http/env.rb,
lib/ddtrace/transport/http/client.rb,
lib/ddtrace/transport/http/traces.rb,
lib/ddtrace/transport/http/api/map.rb,
lib/ddtrace/transport/http/builder.rb,
lib/ddtrace/transport/http/api/spec.rb,
lib/ddtrace/transport/http/response.rb,
lib/ddtrace/transport/http/statistics.rb,
lib/ddtrace/transport/http/adapters/net.rb,
lib/ddtrace/transport/http/api/endpoint.rb,
lib/ddtrace/transport/http/api/instance.rb,
lib/ddtrace/transport/http/adapters/test.rb,
lib/ddtrace/transport/http/api/fallbacks.rb,
lib/ddtrace/transport/http/adapters/registry.rb,
lib/ddtrace/transport/http/adapters/unix_socket.rb

Overview

Namespace for HTTP transport components

Defined Under Namespace

Modules: API, Adapters, Response, Statistics, Traces Classes: Builder, Client, Env

Class Method Summary collapse

Class Method Details

.default(options = {}) ⇒ Object

Builds a new Transport::HTTP::Client with default settings Pass a block to override any settings.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/ddtrace/transport/http.rb', line 27

def default(options = {})
  new do |transport|
    transport.adapter :net_http, default_hostname, default_port
    transport.headers default_headers

    apis = API.defaults

    transport.api API::V4, apis[API::V4], fallback: API::V3, default: true
    transport.api API::V3, apis[API::V3], fallback: API::V2
    transport.api API::V2, apis[API::V2]

    # Apply any settings given by options
    unless options.empty?
      # Change hostname/port
      if options.key?(:hostname) || options.key?(:port)
        hostname = options.fetch(:hostname, default_hostname)
        port = options.fetch(:port, default_port)
        transport.adapter :net_http, hostname, port
      end

      # Change default API
      transport.default_api = options[:api_version] if options.key?(:api_version)

      # Add headers
      transport.headers options[:headers] if options.key?(:headers)

      # Execute on_build callback
      options[:on_build].call(transport) if options[:on_build].is_a?(Proc)
    end

    # Call block to apply any customization, if provided.
    yield(transport) if block_given?
  end
end

.default_headersObject



62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/ddtrace/transport/http.rb', line 62

def default_headers
  {
    Datadog::Ext::Transport::HTTP::HEADER_META_LANG => Datadog::Ext::Runtime::LANG,
    Datadog::Ext::Transport::HTTP::HEADER_META_LANG_VERSION => Datadog::Ext::Runtime::LANG_VERSION,
    Datadog::Ext::Transport::HTTP::HEADER_META_LANG_INTERPRETER => Datadog::Ext::Runtime::LANG_INTERPRETER,
    Datadog::Ext::Transport::HTTP::HEADER_META_TRACER_VERSION => Datadog::Ext::Runtime::TRACER_VERSION
  }.tap do |headers|
    # Add container ID, if present.
    container_id = Datadog::Runtime::Container.container_id
    unless container_id.nil?
      headers[Datadog::Ext::Transport::HTTP::HEADER_CONTAINER_ID] = container_id
    end
  end
end

.default_hostnameObject



77
78
79
# File 'lib/ddtrace/transport/http.rb', line 77

def default_hostname
  ENV.fetch(Datadog::Ext::Transport::HTTP::ENV_DEFAULT_HOST, Datadog::Ext::Transport::HTTP::DEFAULT_HOST)
end

.default_portObject



81
82
83
# File 'lib/ddtrace/transport/http.rb', line 81

def default_port
  ENV.fetch(Datadog::Ext::Transport::HTTP::ENV_DEFAULT_PORT, Datadog::Ext::Transport::HTTP::DEFAULT_PORT).to_i
end

.new(&block) ⇒ Object

Builds a new Transport::HTTP::Client



21
22
23
# File 'lib/ddtrace/transport/http.rb', line 21

def new(&block)
  Builder.new(&block).to_client
end