Class: SplitIoClient::Api::Events
- Defined in:
- lib/splitclient-rb/engine/api/events.rb
Instance Method Summary collapse
-
#initialize(api_key, config, telemetry_runtime_producer) ⇒ Events
constructor
A new instance of Events.
- #post(events) ⇒ Object
Methods inherited from Client
Constructor Details
#initialize(api_key, config, telemetry_runtime_producer) ⇒ Events
Returns a new instance of Events.
6 7 8 9 10 |
# File 'lib/splitclient-rb/engine/api/events.rb', line 6 def initialize(api_key, config, telemetry_runtime_producer) super(config) @api_key = api_key @telemetry_runtime_producer = telemetry_runtime_producer end |
Instance Method Details
#post(events) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/splitclient-rb/engine/api/events.rb', line 12 def post(events) if events.empty? @config.split_logger.log_if_debug('No events to report') return end start = Time.now events.each_slice(@config.events_queue_size) do |events_slice| response = post_api( "#{@config.events_uri}/events/bulk", @api_key, events_slice.map { |event| formatted_event(event[:e]) } ) if response.success? @config.split_logger.log_if_debug("Events reported: #{events_slice.size}") bucket = BinarySearchLatencyTracker.get_bucket((Time.now - start) * 1000.0) @telemetry_runtime_producer.record_sync_latency(Telemetry::Domain::Constants::EVENT_SYNC, bucket) @telemetry_runtime_producer.record_successful_sync(Telemetry::Domain::Constants::EVENT_SYNC, (Time.now.to_f * 1000.0).to_i) else @telemetry_runtime_producer.record_sync_error(Telemetry::Domain::Constants::EVENT_SYNC, response.status) @config.logger.error("Unexpected status code while posting events: #{response.status}." \ ' - Check your API key and base URI') raise 'Split SDK failed to connect to backend to post events' end end end |