Class: SplitIoClient::Telemetry::MemoryRuntimeProducer

Inherits:
Object
  • Object
show all
Defined in:
lib/splitclient-rb/telemetry/memory/memory_runtime_producer.rb

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ MemoryRuntimeProducer

Returns a new instance of MemoryRuntimeProducer.



6
7
8
9
# File 'lib/splitclient-rb/telemetry/memory/memory_runtime_producer.rb', line 6

def initialize(config)
  @config = config
  @adapter = config.telemetry_adapter
end

Instance Method Details

#add_tag(tag) ⇒ Object



11
12
13
14
15
# File 'lib/splitclient-rb/telemetry/memory/memory_runtime_producer.rb', line 11

def add_tag(tag)
  return if tag.length >= 9

  @adapter.tags << tag
end

#record_auth_rejectionsObject



55
56
57
58
59
# File 'lib/splitclient-rb/telemetry/memory/memory_runtime_producer.rb', line 55

def record_auth_rejections
  @adapter.auth_rejections.increment
rescue StandardError => e
  @config.log_found_exception(__method__.to_s, e)
end

#record_events_stats(type, count) ⇒ Object



23
24
25
26
27
# File 'lib/splitclient-rb/telemetry/memory/memory_runtime_producer.rb', line 23

def record_events_stats(type, count)
  @adapter.events_data_records.find { |l| l[:type] == type }[:value].value += count unless count.zero?
rescue StandardError => e
  @config.log_found_exception(__method__.to_s, e)
end

#record_impressions_stats(type, count) ⇒ Object



17
18
19
20
21
# File 'lib/splitclient-rb/telemetry/memory/memory_runtime_producer.rb', line 17

def record_impressions_stats(type, count)
  @adapter.impressions_data_records.find { |l| l[:type] == type }[:value].value += count unless count.zero?
rescue StandardError => e
  @config.log_found_exception(__method__.to_s, e)
end

#record_session_length(session) ⇒ Object



74
75
76
77
78
# File 'lib/splitclient-rb/telemetry/memory/memory_runtime_producer.rb', line 74

def record_session_length(session)
  @adapter.session_length.value = session
rescue StandardError => e
  @config.log_found_exception(__method__.to_s, e)
end

#record_streaming_event(type, data = nil, timestamp = nil) ⇒ Object



67
68
69
70
71
72
# File 'lib/splitclient-rb/telemetry/memory/memory_runtime_producer.rb', line 67

def record_streaming_event(type, data = nil, timestamp = nil)
  timestamp ||= (Time.now.to_f * 1000.0).to_i
  @adapter.streaming_events << { e: type, d: data, t: timestamp } unless @adapter.streaming_events.length >= 19
rescue StandardError => e
  @config.log_found_exception(__method__.to_s, e)
end

#record_successful_sync(type, value = nil) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/splitclient-rb/telemetry/memory/memory_runtime_producer.rb', line 29

def record_successful_sync(type, value = nil)
  value = (Time.now.to_f * 1000.0).to_i if value.nil?

  @adapter.last_synchronization.find { |l| l[:type] == type }[:value] = Concurrent::AtomicFixnum.new(value)
rescue StandardError => e
  @config.log_found_exception(__method__.to_s, e)
end

#record_sync_error(type, status) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/splitclient-rb/telemetry/memory/memory_runtime_producer.rb', line 37

def record_sync_error(type, status)
  http_errors = @adapter.http_errors.find { |l| l[:type] == type }[:value]

  begin
    http_errors[status] += 1
  rescue StandardError => _e
    http_errors[status] = 1
  end
rescue StandardError => e
  @config.log_found_exception(__method__.to_s, e)
end

#record_sync_latency(type, bucket) ⇒ Object



49
50
51
52
53
# File 'lib/splitclient-rb/telemetry/memory/memory_runtime_producer.rb', line 49

def record_sync_latency(type, bucket)
  @adapter.http_latencies.find { |l| l[:type] == type }[:value][bucket] += 1
rescue StandardError => e
  @config.log_found_exception(__method__.to_s, e)
end

#record_token_refreshesObject



61
62
63
64
65
# File 'lib/splitclient-rb/telemetry/memory/memory_runtime_producer.rb', line 61

def record_token_refreshes
  @adapter.token_refreshes.increment
rescue StandardError => e
  @config.log_found_exception(__method__.to_s, e)
end

#record_updates_from_sse(event) ⇒ Object



80
81
82
83
84
# File 'lib/splitclient-rb/telemetry/memory/memory_runtime_producer.rb', line 80

def record_updates_from_sse(event)
  @adapter.updates_from_sse[event] += 1
rescue StandardError => e
  @config.log_found_exception(__method__.to_s, e)
end