Class: BrainzLab::Pulse::Client
- Inherits:
-
Object
- Object
- BrainzLab::Pulse::Client
- Defined in:
- lib/brainzlab/pulse/client.rb
Defined Under Namespace
Classes: RetryableError
Constant Summary collapse
- MAX_RETRIES =
3- RETRY_DELAY =
0.5
Instance Method Summary collapse
- #flush ⇒ Object
-
#initialize(config) ⇒ Client
constructor
A new instance of Client.
- #send_batch(payloads) ⇒ Object
- #send_metric(payload) ⇒ Object
- #send_span(payload) ⇒ Object
- #send_trace(payload) ⇒ Object
Constructor Details
#initialize(config) ⇒ Client
Returns a new instance of Client.
13 14 15 16 17 18 |
# File 'lib/brainzlab/pulse/client.rb', line 13 def initialize(config) @config = config @buffer = [] @mutex = Mutex.new @flush_thread = nil end |
Instance Method Details
#flush ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/brainzlab/pulse/client.rb', line 49 def flush traces_to_send = nil @mutex.synchronize do return if @buffer.empty? traces_to_send = @buffer.dup @buffer.clear end send_batch(traces_to_send) if traces_to_send&.any? end |
#send_batch(payloads) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/brainzlab/pulse/client.rb', line 30 def send_batch(payloads) return unless @config.pulse_enabled && @config.pulse_valid? return if payloads.empty? post('/api/v1/traces/batch', { traces: payloads }) end |
#send_metric(payload) ⇒ Object
37 38 39 40 41 |
# File 'lib/brainzlab/pulse/client.rb', line 37 def send_metric(payload) return unless @config.pulse_enabled && @config.pulse_valid? post('/api/v1/metrics', payload) end |
#send_span(payload) ⇒ Object
43 44 45 46 47 |
# File 'lib/brainzlab/pulse/client.rb', line 43 def send_span(payload) return unless @config.pulse_enabled && @config.pulse_valid? post('/api/v1/spans', payload) end |
#send_trace(payload) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/brainzlab/pulse/client.rb', line 20 def send_trace(payload) return unless @config.pulse_enabled && @config.pulse_valid? if @config.pulse_buffer_size > 1 buffer_trace(payload) else post('/api/v1/traces', payload) end end |