Class: Datadog::CI::Logs::Transport
- Inherits:
-
Object
- Object
- Datadog::CI::Logs::Transport
- Defined in:
- lib/datadog/ci/logs/transport.rb
Constant Summary collapse
- DEFAULT_MAX_PAYLOAD_SIZE =
4.5 * 1024 * 1024
Instance Attribute Summary collapse
-
#api ⇒ Object
readonly
Returns the value of attribute api.
-
#max_payload_size ⇒ Object
readonly
Returns the value of attribute max_payload_size.
Instance Method Summary collapse
-
#initialize(api:, max_payload_size: DEFAULT_MAX_PAYLOAD_SIZE) ⇒ Transport
constructor
A new instance of Transport.
- #send_events(events) ⇒ Object
Constructor Details
#initialize(api:, max_payload_size: DEFAULT_MAX_PAYLOAD_SIZE) ⇒ Transport
Returns a new instance of Transport.
16 17 18 19 |
# File 'lib/datadog/ci/logs/transport.rb', line 16 def initialize(api:, max_payload_size: DEFAULT_MAX_PAYLOAD_SIZE) @api = api @max_payload_size = max_payload_size end |
Instance Attribute Details
#api ⇒ Object (readonly)
Returns the value of attribute api.
13 14 15 |
# File 'lib/datadog/ci/logs/transport.rb', line 13 def api @api end |
#max_payload_size ⇒ Object (readonly)
Returns the value of attribute max_payload_size.
13 14 15 |
# File 'lib/datadog/ci/logs/transport.rb', line 13 def max_payload_size @max_payload_size end |
Instance Method Details
#send_events(events) ⇒ Object
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 47 48 |
# File 'lib/datadog/ci/logs/transport.rb', line 21 def send_events(events) return [] if events.nil? || events.empty? Datadog.logger.debug { "[#{self.class.name}] Sending #{events.count} events..." } encoded_events = events.filter_map do |event| encoded_event = event.to_json if event_too_large?(event, encoded_event) next end encoded_event end responses = [] Datadog::Core::Chunker.chunk_by_size(encoded_events, max_payload_size).map do |chunk| encoded_payload = pack_events(chunk) Datadog.logger.debug do "[#{self.class.name}] Send chunk of #{chunk.count} events; payload size #{encoded_payload.size}" end response = send_payload(encoded_payload) responses << response end responses end |