Class: BoringMetrics::Client
- Inherits:
-
Object
- Object
- BoringMetrics::Client
- Defined in:
- lib/boringmetrics/client.rb
Overview
Main client for the BoringMetrics SDK
Instance Attribute Summary collapse
-
#lives ⇒ Object
readonly
Returns the value of attribute lives.
-
#logs ⇒ Object
readonly
Returns the value of attribute logs.
Instance Method Summary collapse
-
#add_log(log) ⇒ void
Add a log to the queue.
-
#initialize(token, **config) ⇒ Client
constructor
Initialize a new client.
-
#update_live(update) ⇒ void
Update a live metric.
Constructor Details
#initialize(token, **config) ⇒ Client
Initialize a new client
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/boringmetrics/client.rb', line 15 def initialize(token, **config) @config = Configuration.new(token, **config) @transport = Transport.new(@config) @logs_queue = Concurrent::Array.new @logs_mutex = Mutex.new @logs_timer = nil @lives_queue = Concurrent::Array.new @lives_mutex = Mutex.new @lives_timer = nil @logs = LogMethods.new(self) @lives = LiveMethods.new(self) end |
Instance Attribute Details
#lives ⇒ Object (readonly)
Returns the value of attribute lives.
9 10 11 |
# File 'lib/boringmetrics/client.rb', line 9 def lives @lives end |
#logs ⇒ Object (readonly)
Returns the value of attribute logs.
9 10 11 |
# File 'lib/boringmetrics/client.rb', line 9 def logs @logs end |
Instance Method Details
#add_log(log) ⇒ void
This method returns an undefined value.
Add a log to the queue
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/boringmetrics/client.rb', line 35 def add_log(log) log_with_sent_at = log.dup # Support both snake_case and camelCase if log_with_sent_at[:sentAt].nil? && log_with_sent_at[:sent_at].nil? log_with_sent_at[:sentAt] = Time.now.iso8601 elsif log_with_sent_at[:sent_at] && log_with_sent_at[:sentAt].nil? log_with_sent_at[:sentAt] = log_with_sent_at[:sent_at] end @logs_mutex.synchronize do @logs_queue << log_with_sent_at if @logs_queue.size >= @config.logsMaxBatchSize flush_logs elsif @logs_timer.nil? schedule_logs_flush end end end |
#update_live(update) ⇒ void
This method returns an undefined value.
Update a live metric
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/boringmetrics/client.rb', line 60 def update_live(update) update_with_sent_at = update.dup # Support both snake_case and camelCase if update_with_sent_at[:sentAt].nil? && update_with_sent_at[:sent_at].nil? update_with_sent_at[:sentAt] = Time.now.iso8601 elsif update_with_sent_at[:sent_at] && update_with_sent_at[:sentAt].nil? update_with_sent_at[:sentAt] = update_with_sent_at[:sent_at] end @lives_mutex.synchronize do @lives_queue << update_with_sent_at if @lives_queue.size >= @config.livesMaxBatchSize flush_lives elsif @lives_timer.nil? schedule_lives_flush end end end |