Class: CloseYourIt::Transport
- Inherits:
-
Object
- Object
- CloseYourIt::Transport
- Defined in:
- lib/closeyourit/transport.rb
Overview
Spedisce un payload a un path di ingest (errori → /events, metriche → /metrics) via HTTP POST
con Authorization: Bearer. Mai solleva: ogni errore di rete è loggato e ingoiato.
Constant Summary collapse
- OPEN_TIMEOUT =
2- READ_TIMEOUT =
3- MAX_REDIRECTS =
Net::HTTP non segue i redirect: l'host canonico può rispondere 301 (es. apex → www). Ri-POSTiamo a Location preservando metodo + body, così l'evento non si perde in silenzio.
2
Instance Method Summary collapse
-
#initialize(configuration) ⇒ Transport
constructor
A new instance of Transport.
- #send_event(payload, path:) ⇒ Object
Constructor Details
#initialize(configuration) ⇒ Transport
Returns a new instance of Transport.
17 18 19 |
# File 'lib/closeyourit/transport.rb', line 17 def initialize(configuration) @configuration = configuration end |
Instance Method Details
#send_event(payload, path:) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/closeyourit/transport.rb', line 21 def send_event(payload, path:) response = post(payload, path) if response.is_a?(Net::HTTPSuccess) CloseYourIt.stats.increment(:sent) else CloseYourIt.stats.increment(:failed) CloseYourIt.internal_logger.warn("CloseYourIt transport: HTTP #{response.code} su #{path}") end response rescue StandardError => e CloseYourIt.stats.increment(:failed) CloseYourIt.internal_logger.error("CloseYourIt transport: #{e.class}: #{e.}") nil end |