Class: Datadog::Core::Transport::HTTP::Client Private
- Inherits:
-
Object
- Object
- Datadog::Core::Transport::HTTP::Client
- Defined in:
- lib/datadog/core/transport/http/client.rb
Overview
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.
Routes, encodes, and sends DI data to the trace agent via HTTP.
Direct Known Subclasses
Instance Attribute Summary collapse
- #instance ⇒ Object readonly private
- #logger ⇒ Object readonly private
Instance Method Summary collapse
- #build_env(request) ⇒ Object private
- #build_exception_message(exception) ⇒ Object private
-
#initialize(instance, logger:) ⇒ Client
constructor
private
A new instance of Client.
-
#on_exception(exception) ⇒ Object
private
Callback that is invoked if a request failed with an exception.
-
#on_response(response) ⇒ Object
private
Callback that is invoked if a request did not raise an exception (but did not necessarily complete successfully).
- #send_request(action, request) ⇒ Object private
Constructor Details
#initialize(instance, logger:) ⇒ Client
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 Client.
16 17 18 19 |
# File 'lib/datadog/core/transport/http/client.rb', line 16 def initialize(instance, logger:) @instance = instance @logger = logger end |
Instance Attribute Details
#instance ⇒ Object (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.
14 15 16 |
# File 'lib/datadog/core/transport/http/client.rb', line 14 def instance @instance end |
#logger ⇒ Object (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.
14 15 16 |
# File 'lib/datadog/core/transport/http/client.rb', line 14 def logger @logger end |
Instance Method Details
#build_env(request) ⇒ 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.
48 49 50 |
# File 'lib/datadog/core/transport/http/client.rb', line 48 def build_env(request) Datadog::Core::Transport::HTTP::Env.new(request) end |
#build_exception_message(exception) ⇒ 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.
72 73 74 75 |
# File 'lib/datadog/core/transport/http/client.rb', line 72 def (exception) "Internal error during #{self.class.name} request. Cause: #{exception.class}: #{exception} " \ "Location: #{Array(exception.backtrace).first}" end |
#on_exception(exception) ⇒ 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.
Callback that is invoked if a request failed with an exception.
Override in subclasses.
66 67 68 69 70 |
# File 'lib/datadog/core/transport/http/client.rb', line 66 def on_exception(exception) = (exception) logger.debug() end |
#on_response(response) ⇒ 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.
Callback that is invoked if a request did not raise an exception (but did not necessarily complete successfully).
Override in subclasses.
Note that the client will return the original response - the return value of this method is ignored, and response should not be modified.
60 61 |
# File 'lib/datadog/core/transport/http/client.rb', line 60 def on_response(response) end |
#send_request(action, request) ⇒ 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.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/datadog/core/transport/http/client.rb', line 21 def send_request(action, request) # Build request into env env = build_env(request) # Get responses from API. # All of our APIs send only one type of request each. instance.endpoint.call(env) do |request_env| instance.call(request_env) end.tap do |response| unless response.ok? # This logging is on debug level. # To report the failed operations on lower levels, # throttling needs to be implemented because # agent unavailability can produce a lot of spam that would # be not desired by customers. # Some transports do report failed operations on warn level # with such throttling. logger.debug { "send_request #{action.inspect} failed: #{response.inspect}" } end on_response(response) end rescue => exception on_exception(exception) Datadog::Core::Transport::InternalErrorResponse.new(exception) end |