Class: Datadog::DI::Transport::Diagnostics::Transport Private

Inherits:
Object
  • Object
show all
Defined in:
lib/datadog/di/transport/diagnostics.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(apis, default_api, logger:) ⇒ Transport

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Transport.


20
21
22
23
24
25
# File 'lib/datadog/di/transport/diagnostics.rb', line 20

def initialize(apis, default_api, logger:)
  @apis = apis
  @logger = logger

  @client = HTTP::Client.new(current_api, logger: logger)
end

Instance Attribute Details

#apisObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


18
19
20
# File 'lib/datadog/di/transport/diagnostics.rb', line 18

def apis
  @apis
end

#clientObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


18
19
20
# File 'lib/datadog/di/transport/diagnostics.rb', line 18

def client
  @client
end

#current_api_idObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


18
19
20
# File 'lib/datadog/di/transport/diagnostics.rb', line 18

def current_api_id
  @current_api_id
end

#default_apiObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


18
19
20
# File 'lib/datadog/di/transport/diagnostics.rb', line 18

def default_api
  @default_api
end

#loggerObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


18
19
20
# File 'lib/datadog/di/transport/diagnostics.rb', line 18

def logger
  @logger
end

Instance Method Details

#current_apiObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


27
28
29
# File 'lib/datadog/di/transport/diagnostics.rb', line 27

def current_api
  @apis[HTTP::API::DIAGNOSTICS]
end

#send_diagnostics(payload) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


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
# File 'lib/datadog/di/transport/diagnostics.rb', line 31

def send_diagnostics(payload)
  json = JSON.dump(payload)
  parcel = EncodedParcel.new(json)
  request = Request.new(parcel)

  response = @client.send_diagnostics_payload(request)
  unless response.ok?
    # TODO Datadog::Core::Transport::InternalErrorResponse
    # does not have +code+ method, what is the actual API of
    # these response objects?
    raise Error::AgentCommunicationError, "send_diagnostics failed: #{begin
      response.code
    rescue
      "???"
    end}: #{response.payload}"
  end
rescue Error::AgentCommunicationError
  raise
# Datadog::Core::Transport does not perform any exception mapping,
# therefore we could have any exception here from failure to parse
# agent URI for example.
# If we ever implement retries for network errors, we should distinguish
# actual network errors from non-network errors that are raised by
# transport code.
rescue => exc
  raise Error::AgentCommunicationError, "send_diagnostics failed: #{exc.class}: #{exc}"
end