Class: Bitfab::Otel::DirectExporter

Inherits:
Object
  • Object
show all
Defined in:
lib/bitfab/otel.rb

Overview

Encodes carrier spans as OTLP/JSON and posts them straight to Bitfab.

Instance Method Summary collapse

Constructor Details

#initialize(direct_sender:, max_request_bytes:, max_request_batch_size:, export_concurrency:, on_delivered: nil) ⇒ DirectExporter

Returns a new instance of DirectExporter.



205
206
207
208
209
210
211
212
213
214
215
216
# File 'lib/bitfab/otel.rb', line 205

def initialize(direct_sender:, max_request_bytes:, max_request_batch_size:, export_concurrency:, on_delivered: nil)
  @direct_sender = direct_sender
  @on_delivered = on_delivered
  @max_request_bytes = max_request_bytes
  @max_request_batch_size = max_request_batch_size
  @export_concurrency = export_concurrency
  # Eager, unlike the module-level mutexes: this one is first touched by
  # the export threads fanning out a batch, and `||=` racing between them
  # would hand each a different mutex and no mutual exclusion at all.
  @throttle_mutex = Mutex.new
  @throttled_until = 0.0
end

Instance Method Details

#export(spans, timeout: nil) ⇒ Object



218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
# File 'lib/bitfab/otel.rb', line 218

def export(spans, timeout: nil)
  spans = spans.to_a
  return SUCCESS if spans.empty?

  begin
    encoded = spans.map { |span| Encoder.encode_span(span) }
    envelope = Encoder.request_envelope(spans.first)
  rescue => e
    Bitfab.warn_once(
      "otel-encode-failed",
      "failed to encode an OpenTelemetry span batch (#{e.message})"
    )
    return FAILURE
  end

  batches = build_request_batches(envelope, encoded)
  results = send_batches(envelope, batches)
  results.all? ? SUCCESS : FAILURE
end

#force_flush(timeout: nil) ⇒ Object



238
239
240
# File 'lib/bitfab/otel.rb', line 238

def force_flush(timeout: nil)
  SUCCESS
end

#shutdown(timeout: nil) ⇒ Object



242
243
244
# File 'lib/bitfab/otel.rb', line 242

def shutdown(timeout: nil)
  SUCCESS
end