Class: Datadog::Core::Telemetry::Http::Adapters::Net
- Inherits:
-
Object
- Object
- Datadog::Core::Telemetry::Http::Adapters::Net
- Defined in:
- lib/datadog/core/telemetry/http/adapters/net.rb
Overview
Class defining methods to make http requests via NET
Defined Under Namespace
Classes: Response
Constant Summary collapse
- DEFAULT_TIMEOUT =
2
Instance Attribute Summary collapse
-
#hostname ⇒ Object
readonly
Returns the value of attribute hostname.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#ssl ⇒ Object
readonly
Returns the value of attribute ssl.
-
#timeout ⇒ Object
readonly
Returns the value of attribute timeout.
Instance Method Summary collapse
-
#initialize(hostname:, port: nil, timeout: DEFAULT_TIMEOUT, ssl: true) ⇒ Net
constructor
A new instance of Net.
- #open(&block) ⇒ Object
- #post(env) ⇒ Object
Constructor Details
#initialize(hostname:, port: nil, timeout: DEFAULT_TIMEOUT, ssl: true) ⇒ Net
Returns a new instance of Net.
18 19 20 21 22 23 |
# File 'lib/datadog/core/telemetry/http/adapters/net.rb', line 18 def initialize(hostname:, port: nil, timeout: DEFAULT_TIMEOUT, ssl: true) @hostname = hostname @port = port @timeout = timeout @ssl = ssl.nil? ? true : ssl end |
Instance Attribute Details
#hostname ⇒ Object (readonly)
Returns the value of attribute hostname.
10 11 12 |
# File 'lib/datadog/core/telemetry/http/adapters/net.rb', line 10 def hostname @hostname end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
10 11 12 |
# File 'lib/datadog/core/telemetry/http/adapters/net.rb', line 10 def port @port end |
#ssl ⇒ Object (readonly)
Returns the value of attribute ssl.
10 11 12 |
# File 'lib/datadog/core/telemetry/http/adapters/net.rb', line 10 def ssl @ssl end |
#timeout ⇒ Object (readonly)
Returns the value of attribute timeout.
10 11 12 |
# File 'lib/datadog/core/telemetry/http/adapters/net.rb', line 10 def timeout @timeout end |
Instance Method Details
#open(&block) ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/datadog/core/telemetry/http/adapters/net.rb', line 25 def open(&block) req = ::Net::HTTP.new(@hostname, @port) req.use_ssl = @ssl req.open_timeout = req.read_timeout = @timeout req.start(&block) end |
#post(env) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/datadog/core/telemetry/http/adapters/net.rb', line 34 def post(env) begin post = ::Net::HTTP::Post.new(env.path, env.headers) post.body = env.body http_response = open do |http| http.request(post) end Response.new(http_response) rescue StandardError => e Datadog.logger.debug("Unable to send telemetry event to agent: #{e}") Telemetry::Http::InternalErrorResponse.new(e) end end |