Class: Logtide::Transport::HTTP
- Inherits:
-
Object
- Object
- Logtide::Transport::HTTP
- Defined in:
- lib/logtide/transport/http.rb
Overview
Stateless HTTP sender: one POST per batch to the ingest endpoint (spec 002 sections 1-4). Buffering, batching and retries live in the Batcher; this class just speaks HTTP and never raises for HTTP status codes.
Constant Summary collapse
- GZIP_THRESHOLD =
1024 * 1024
- USER_AGENT =
"logtide-ruby/#{Logtide::VERSION}".freeze
- NETWORK_ERRORS =
[ Errno::ECONNREFUSED, Errno::ECONNRESET, Errno::EHOSTUNREACH, Errno::ENETUNREACH, Errno::ETIMEDOUT, Errno::EPIPE, SocketError, Timeout::Error, EOFError, IOError ].freeze
Instance Method Summary collapse
-
#deliver(logs) ⇒ Object
Delivers the batch and returns a Response, or raises NetworkError.
-
#initialize(url:, api_key:, timeout: 10) ⇒ HTTP
constructor
A new instance of HTTP.
Constructor Details
#initialize(url:, api_key:, timeout: 10) ⇒ HTTP
Returns a new instance of HTTP.
35 36 37 38 39 |
# File 'lib/logtide/transport/http.rb', line 35 def initialize(url:, api_key:, timeout: 10) @uri = URI.parse(url) @api_key = api_key @timeout = timeout end |
Instance Method Details
#deliver(logs) ⇒ Object
Delivers the batch and returns a Response, or raises NetworkError.
42 43 44 45 46 47 48 |
# File 'lib/logtide/transport/http.rb', line 42 def deliver(logs) body = JSON.generate("logs" => logs) response = client.request(build_request(body)) Response.new(status: response.code.to_i, retry_after: parse_retry_after(response["retry-after"])) rescue *NETWORK_ERRORS => e raise NetworkError, e. end |