Class: Errsight::Client
- Inherits:
-
Object
- Object
- Errsight::Client
- Defined in:
- lib/errsight/client.rb
Class Method Summary collapse
-
.cert_store ⇒ Object
Cached once at process boot — set_default_paths reads the system trust store from disk and is expensive to redo per request.
Instance Method Summary collapse
- #enqueue(event) ⇒ Object
- #flush! ⇒ Object
-
#initialize(config) ⇒ Client
constructor
A new instance of Client.
- #shutdown! ⇒ Object
Constructor Details
#initialize(config) ⇒ Client
Returns a new instance of Client.
8 9 10 11 12 13 |
# File 'lib/errsight/client.rb', line 8 def initialize(config) @config = config @queue = [] @mutex = Mutex.new start_flush_worker end |
Class Method Details
.cert_store ⇒ Object
Cached once at process boot — set_default_paths reads the system trust store from disk and is expensive to redo per request.
56 57 58 |
# File 'lib/errsight/client.rb', line 56 def self.cert_store @cert_store ||= OpenSSL::X509::Store.new.tap(&:set_default_paths) end |
Instance Method Details
#enqueue(event) ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/errsight/client.rb', line 15 def enqueue(event) @mutex.synchronize do if @queue.size >= @config.max_queue_size @config.logger&.warn("[Errsight] Queue full (#{@config.max_queue_size}), dropping event") return end @queue << event end end |
#flush! ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/errsight/client.rb', line 25 def flush! events = nil @mutex.synchronize do return if @queue.empty? events = @queue.slice!(0, @config.batch_size) end send_events(events) if events&.any? end |
#shutdown! ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/errsight/client.rb', line 34 def shutdown! @flush_thread&.exit flush! # Drain remaining events synchronously @http_mutex.synchronize { @http&.finish if @http&.started? } rescue StandardError # best-effort end |