Module: Datadog::Core::Transport::HTTP

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

Overview

HTTP transport

Defined Under Namespace

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

Class Method Summary collapse

Class Method Details

.build(agent_settings:, logger: Datadog.logger, headers: nil, &block) ⇒ Object

Helper function that delegates to Builder.new but is under HTTP namespace so that client code requires this file to get the adapters configured, and not the builder directly.



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/datadog/core/transport/http.rb', line 32

def build(
  agent_settings:,
  logger: Datadog.logger,
  headers: nil,
  &block
)
  Builder.new(logger: logger) do |transport|
    transport.adapter(agent_settings)
    transport.headers(default_headers)

    # The caller must define APIs before we set the default API.
    yield transport

    # Apply any settings given by options
    transport.headers(headers) if headers
  end
end

.default_headersObject



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/datadog/core/transport/http.rb', line 50

def default_headers
  {
    Core::Transport::Ext::HTTP::HEADER_CLIENT_COMPUTED_TOP_LEVEL => '1',
    Core::Transport::Ext::HTTP::HEADER_META_LANG =>
      Datadog::Core::Environment::Ext::LANG,
    Core::Transport::Ext::HTTP::HEADER_META_LANG_VERSION =>
      Datadog::Core::Environment::Ext::LANG_VERSION,
    Core::Transport::Ext::HTTP::HEADER_META_LANG_INTERPRETER =>
      Datadog::Core::Environment::Ext::LANG_INTERPRETER,
    Core::Transport::Ext::HTTP::HEADER_META_LANG_INTERPRETER_VENDOR =>
      Core::Environment::Ext::LANG_ENGINE,
    Core::Transport::Ext::HTTP::HEADER_META_TRACER_VERSION =>
      Datadog::Core::Environment::Ext::GEM_DATADOG_VERSION
  }.tap do |headers|
    # Add application container info
    headers.merge!(Core::Environment::Container.to_headers)

    # TODO: inject configuration rather than reading from global here
    unless Datadog.configuration.apm.tracing.enabled
      # Sending this header to the agent will disable metrics computation (and billing) on the agent side
      # by pretending it has already been done on the library side.
      headers[Core::Transport::Ext::HTTP::HEADER_CLIENT_COMPUTED_STATS] = 'yes'
    end
  end
end