Class: Vivarium::OtelHttpExporter
- Inherits:
-
Object
- Object
- Vivarium::OtelHttpExporter
- Defined in:
- lib/vivarium/otel_stream.rb
Overview
Background OTLP/HTTP(JSON) sender. Completed spans are enqueued and flushed in batches by a worker thread to endpoint/v1/traces. Send failures are logged and the batch is dropped so a resident observation never stalls.
Instance Method Summary collapse
- #enqueue(span) ⇒ Object
-
#initialize(endpoint:, flush_interval: 2.0, max_batch: 256, max_queue: 10_000) ⇒ OtelHttpExporter
constructor
A new instance of OtelHttpExporter.
- #shutdown ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize(endpoint:, flush_interval: 2.0, max_batch: 256, max_queue: 10_000) ⇒ OtelHttpExporter
Returns a new instance of OtelHttpExporter.
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/vivarium/otel_stream.rb', line 12 def initialize(endpoint:, flush_interval: 2.0, max_batch: 256, max_queue: 10_000) @uri = build_uri(endpoint) @flush_interval = flush_interval @max_batch = max_batch @max_queue = max_queue @queue = [] @mutex = Mutex.new @cond = ConditionVariable.new @stop = false @dropped = 0 @thread = nil end |
Instance Method Details
#enqueue(span) ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/vivarium/otel_stream.rb', line 33 def enqueue(span) @mutex.synchronize do if @queue.size >= @max_queue @dropped += 1 else @queue << span @cond.signal end end end |
#shutdown ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/vivarium/otel_stream.rb', line 44 def shutdown @mutex.synchronize do @stop = true @cond.signal end @thread&.join warn "[vivarium] otel: dropped #{@dropped} span(s) (queue overflow)" if @dropped.positive? end |
#start ⇒ Object
26 27 28 29 30 31 |
# File 'lib/vivarium/otel_stream.rb', line 26 def start return self if @thread @thread = Thread.new { worker } self end |