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:) ⇒ DirectExporter

Returns a new instance of DirectExporter.



228
229
230
231
232
233
# File 'lib/bitfab/otel.rb', line 228

def initialize(direct_sender:, max_request_bytes:, max_request_batch_size:, export_concurrency:)
  @direct_sender = direct_sender
  @max_request_bytes = max_request_bytes
  @max_request_batch_size = max_request_batch_size
  @export_concurrency = export_concurrency
end

Instance Method Details

#export(spans, timeout: nil) ⇒ Object



235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
# File 'lib/bitfab/otel.rb', line 235

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

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

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

#force_flush(timeout: nil) ⇒ Object



254
255
256
# File 'lib/bitfab/otel.rb', line 254

def force_flush(timeout: nil)
  SUCCESS
end

#shutdown(timeout: nil) ⇒ Object



258
259
260
# File 'lib/bitfab/otel.rb', line 258

def shutdown(timeout: nil)
  SUCCESS
end