Class: Foam::Otel::BeforeSend::LogRecordExporter

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

Instance Method Summary collapse

Constructor Details

#initialize(inner, config) ⇒ LogRecordExporter

Returns a new instance of LogRecordExporter.



259
260
261
262
# File 'lib/foam/otel/before_send.rb', line 259

def initialize(inner, config)
  @inner = inner
  @hooks = config.before_send
end

Instance Method Details

#export(log_record_data, timeout: nil) ⇒ Object



264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
# File 'lib/foam/otel/before_send.rb', line 264

def export(log_record_data, timeout: nil)
  batch = log_record_data.to_a
  faults = []
  kept = batch.filter_map do |lrd|
    result = BeforeSend.run(@hooks, lrd, :log, faults)
    result.equal?(ERROR) ? nil : result
  end
  unless faults.empty?
    Diagnostics.warn("before_send faulted for #{faults.length} log record(s) — dropped, never " \
                     "exported half-transformed (fail-closed, rule 14): #{faults.uniq.take(3).join(', ')}")
  end
  status = kept.empty? ? OpenTelemetry::SDK::Logs::Export::SUCCESS : @inner.export(kept, timeout: timeout)
  faults.empty? ? status : OpenTelemetry::SDK::Logs::Export::FAILURE
rescue StandardError, SystemStackError
  Diagnostics.warn("before_send pass raised past its guards — log batch dropped (fail-closed, rule 14/15)")
  OpenTelemetry::SDK::Logs::Export::FAILURE
end

#force_flush(timeout: nil) ⇒ Object



282
# File 'lib/foam/otel/before_send.rb', line 282

def force_flush(timeout: nil) = @inner.force_flush(timeout: timeout)

#shutdown(timeout: nil) ⇒ Object



283
# File 'lib/foam/otel/before_send.rb', line 283

def shutdown(timeout: nil) = @inner.shutdown(timeout: timeout)