Sha256: d0e2235ea5181a1f9b2951d0e2323babd592060055973d9552a598cb0ed0231d

Contents?: true

Size: 1.41 KB

Versions: 68

Compression:

Stored size: 1.41 KB

Contents

# frozen_string_literal: true

module SplitIoClient
  module Api
    class TelemetryApi < Client
      def initialize(config, api_key, telemetry_runtime_producer)
        super(config)
        @api_key = api_key
        @telemetry_runtime_producer = telemetry_runtime_producer
      end

      def record_init(config_init)
        post_telemetry("#{@config.telemetry_service_url}/metrics/config", config_init, 'init')
      end

      def record_stats(stats)
        post_telemetry("#{@config.telemetry_service_url}/metrics/usage", stats, 'stats')
      end

      private

      def post_telemetry(url, obj, method)
        start = Time.now
        response = post_api(url, @api_key, obj)

        if response.success?
          @config.split_logger.log_if_debug("Telemetry post succeeded: record #{method}.")
          
          bucket = BinarySearchLatencyTracker.get_bucket((Time.now - start) * 1000.0)
          @telemetry_runtime_producer.record_sync_latency(Telemetry::Domain::Constants::TELEMETRY_SYNC, bucket)
          @telemetry_runtime_producer.record_successful_sync(Telemetry::Domain::Constants::TELEMETRY_SYNC, (Time.now.to_f * 1000.0).to_i)
        else
          @telemetry_runtime_producer.record_sync_error(Telemetry::Domain::Constants::TELEMETRY_SYNC, response.status)
          @config.logger.error("Unexpected status code while posting telemetry #{method}: #{response.status}.")
        end
      end
    end
  end
end

Version data entries

68 entries across 68 versions & 1 rubygems

Version Path
splitclient-rb-7.3.4-java lib/splitclient-rb/engine/api/telemetry_api.rb
splitclient-rb-7.3.4 lib/splitclient-rb/engine/api/telemetry_api.rb
splitclient-rb-7.3.4.pre.rc2-java lib/splitclient-rb/engine/api/telemetry_api.rb
splitclient-rb-7.3.4.pre.rc2 lib/splitclient-rb/engine/api/telemetry_api.rb
splitclient-rb-7.3.4.pre.rc1-java lib/splitclient-rb/engine/api/telemetry_api.rb
splitclient-rb-7.3.4.pre.rc1 lib/splitclient-rb/engine/api/telemetry_api.rb
splitclient-rb-7.3.3-java lib/splitclient-rb/engine/api/telemetry_api.rb
splitclient-rb-7.3.3 lib/splitclient-rb/engine/api/telemetry_api.rb
splitclient-rb-7.3.3.pre.rc18-java lib/splitclient-rb/engine/api/telemetry_api.rb
splitclient-rb-7.3.3.pre.rc18 lib/splitclient-rb/engine/api/telemetry_api.rb
splitclient-rb-7.3.3.pre.rc17-java lib/splitclient-rb/engine/api/telemetry_api.rb
splitclient-rb-7.3.3.pre.rc17 lib/splitclient-rb/engine/api/telemetry_api.rb
splitclient-rb-7.3.3.pre.rc16-java lib/splitclient-rb/engine/api/telemetry_api.rb
splitclient-rb-7.3.3.pre.rc16 lib/splitclient-rb/engine/api/telemetry_api.rb
splitclient-rb-7.3.3.pre.rc15-java lib/splitclient-rb/engine/api/telemetry_api.rb
splitclient-rb-7.3.3.pre.rc15 lib/splitclient-rb/engine/api/telemetry_api.rb
splitclient-rb-7.3.3.pre.rc14-java lib/splitclient-rb/engine/api/telemetry_api.rb
splitclient-rb-7.3.3.pre.rc14 lib/splitclient-rb/engine/api/telemetry_api.rb
splitclient-rb-7.3.3.pre.rc13-java lib/splitclient-rb/engine/api/telemetry_api.rb
splitclient-rb-7.3.3.pre.rc13 lib/splitclient-rb/engine/api/telemetry_api.rb