Class: Bitfab::Otel::SizeLimitedExporter

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

Overview

Splits an export into requests no larger than the configured byte target before handing them to the wrapped Collector exporter.

Instance Method Summary collapse

Constructor Details

#initialize(exporter, max_request_bytes) ⇒ SizeLimitedExporter

Returns a new instance of SizeLimitedExporter.



392
393
394
395
396
397
398
# File 'lib/bitfab/otel.rb', line 392

def initialize(exporter, max_request_bytes)
  @exporter = exporter
  @max_request_bytes = max_request_bytes
  # The OTLP gem exposes no public way to measure an encoded request, so
  # requests are partitioned by count alone when its encoder is missing.
  @measurable = exporter.respond_to?(:encode, true)
end

Instance Method Details

#export(spans, timeout: nil) ⇒ Object



400
401
402
403
404
405
406
# File 'lib/bitfab/otel.rb', line 400

def export(spans, timeout: nil)
  batches = partition(spans.to_a)
  batches.reduce(SUCCESS) do |result, batch|
    exported = @exporter.export(batch, timeout:)
    (exported == SUCCESS) ? result : FAILURE
  end
end

#force_flush(timeout: nil) ⇒ Object



408
409
410
# File 'lib/bitfab/otel.rb', line 408

def force_flush(timeout: nil)
  @exporter.force_flush(timeout:)
end

#shutdown(timeout: nil) ⇒ Object



412
413
414
# File 'lib/bitfab/otel.rb', line 412

def shutdown(timeout: nil)
  @exporter.shutdown(timeout:)
end