Class: Datadog::Core::Telemetry::Http::Transport

Inherits:
Object
  • Object
show all
Defined in:
lib/datadog/core/telemetry/http/transport.rb

Overview

Class to send telemetry data to Telemetry API Currently only supports the HTTP protocol.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host:, port:, path:, ssl: false, api_key: nil) ⇒ Transport

Returns a new instance of Transport.



47
48
49
50
51
52
53
# File 'lib/datadog/core/telemetry/http/transport.rb', line 47

def initialize(host:, port:, path:, ssl: false, api_key: nil)
  @host = host
  @port = port
  @ssl = ssl
  @path = path
  @api_key = api_key
end

Instance Attribute Details

#api_keyObject (readonly)

Returns the value of attribute api_key.



40
41
42
# File 'lib/datadog/core/telemetry/http/transport.rb', line 40

def api_key
  @api_key
end

#hostObject (readonly)

Returns the value of attribute host.



40
41
42
# File 'lib/datadog/core/telemetry/http/transport.rb', line 40

def host
  @host
end

#pathObject (readonly)

Returns the value of attribute path.



40
41
42
# File 'lib/datadog/core/telemetry/http/transport.rb', line 40

def path
  @path
end

#portObject (readonly)

Returns the value of attribute port.



40
41
42
# File 'lib/datadog/core/telemetry/http/transport.rb', line 40

def port
  @port
end

#sslObject (readonly)

Returns the value of attribute ssl.



40
41
42
# File 'lib/datadog/core/telemetry/http/transport.rb', line 40

def ssl
  @ssl
end

Class Method Details

.build_agent_transport(agent_settings) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/datadog/core/telemetry/http/transport.rb', line 17

def self.build_agent_transport(agent_settings)
  Transport.new(
    host: agent_settings.hostname,
    port: agent_settings.port,
    path: Http::Ext::AGENT_ENDPOINT
  )
end

.build_agentless_transport(api_key:, dd_site:, url_override: nil) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/datadog/core/telemetry/http/transport.rb', line 25

def self.build_agentless_transport(api_key:, dd_site:, url_override: nil)
  url = url_override || "https://#{Http::Ext::AGENTLESS_HOST_PREFIX}.#{dd_site}:443"

  uri = URI.parse(url)
  raise "Invalid agentless mode URL: #{url}" if uri.host.nil?

  Transport.new(
    host: uri.host,
    port: uri.port || 80,
    path: Http::Ext::AGENTLESS_ENDPOINT,
    ssl: uri.scheme == 'https' || uri.port == 443,
    api_key: api_key
  )
end

Instance Method Details

#request(request_type:, payload:) ⇒ Object



55
56
57
58
59
60
61
# File 'lib/datadog/core/telemetry/http/transport.rb', line 55

def request(request_type:, payload:)
  env = Http::Env.new
  env.path = @path
  env.body = payload
  env.headers = headers(request_type: request_type)
  adapter.post(env)
end