Module: Datadog::Tracing::Transport::HTTP

Defined in:
lib/datadog/tracing/transport/http.rb,
lib/datadog/tracing/transport/http/api.rb,
lib/datadog/tracing/transport/http/client.rb,
lib/datadog/tracing/transport/http/traces.rb,
lib/datadog/tracing/transport/http/builder.rb,
lib/datadog/tracing/transport/http/api/spec.rb,
lib/datadog/tracing/transport/http/statistics.rb,
lib/datadog/tracing/transport/http/api/instance.rb

Overview

Namespace for HTTP transport components

Defined Under Namespace

Modules: API, Statistics, Traces Classes: Builder, Client

Constant Summary collapse

DO_NOT_USE_ENVIRONMENT_AGENT_SETTINGS =

NOTE: Due to… legacy reasons… This class likes having a default ‘AgentSettings` instance to fall back to. Because we generate this instance with an empty instance of `Settings`, the resulting `AgentSettings` below represents only settings specified via environment variables + the usual defaults.

DO NOT USE THIS IN NEW CODE, as it ignores any settings specified by users via ‘Datadog.configure`.

Datadog::Core::Configuration::AgentSettingsResolver.call(
  Datadog::Core::Configuration::Settings.new,
  logger: nil,
)

Class Method Summary collapse

Class Method Details

.default(agent_settings: DO_NOT_USE_ENVIRONMENT_AGENT_SETTINGS, **options) ⇒ Object

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



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/datadog/tracing/transport/http.rb', line 39

def default(
  agent_settings: DO_NOT_USE_ENVIRONMENT_AGENT_SETTINGS,
  **options
)
  new do |transport|
    transport.adapter(agent_settings)
    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]

    # Apply any settings given by options
    unless options.empty?
      transport.default_api = options[:api_version] if options.key?(:api_version)
      transport.headers options[:headers] if options.key?(:headers)
    end

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

.default_adapterObject



84
85
86
# File 'lib/datadog/tracing/transport/http.rb', line 84

def default_adapter
  Datadog::Core::Configuration::Ext::Agent::HTTP::ADAPTER
end

.default_headersObject



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/datadog/tracing/transport/http.rb', line 63

def default_headers
  {
    Datadog::Core::Transport::Ext::HTTP::HEADER_CLIENT_COMPUTED_TOP_LEVEL => '1',
    Datadog::Core::Transport::Ext::HTTP::HEADER_META_LANG => Datadog::Core::Environment::Ext::LANG,
    Datadog::Core::Transport::Ext::HTTP::HEADER_META_LANG_VERSION => Datadog::Core::Environment::Ext::LANG_VERSION,
    Datadog::Core::Transport::Ext::HTTP::HEADER_META_LANG_INTERPRETER =>
      Datadog::Core::Environment::Ext::LANG_INTERPRETER,
    Datadog::Core::Transport::Ext::HTTP::HEADER_META_LANG_INTERPRETER_VENDOR => Core::Environment::Ext::LANG_ENGINE,
    Datadog::Core::Transport::Ext::HTTP::HEADER_META_TRACER_VERSION =>
      Datadog::Core::Environment::Ext::GEM_DATADOG_VERSION
  }.tap do |headers|
    # Add container ID, if present.
    container_id = Datadog::Core::Environment::Container.container_id
    headers[Datadog::Core::Transport::Ext::HTTP::HEADER_CONTAINER_ID] = container_id unless container_id.nil?
    # Pretend that stats computation are already done by the client
    if Datadog.configuration.appsec.standalone.enabled
      headers[Datadog::Core::Transport::Ext::HTTP::HEADER_CLIENT_COMPUTED_STATS] = 'yes'
    end
  end
end

.new(&block) ⇒ Object

Builds a new Transport::HTTP::Client



33
34
35
# File 'lib/datadog/tracing/transport/http.rb', line 33

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