Class: Mergify::RSpec::SynchronousBatchSpanProcessor

Inherits:
OpenTelemetry::SDK::Trace::Export::SimpleSpanProcessor
  • Object
show all
Defined in:
lib/mergify/rspec/synchronous_batch_span_processor.rb

Overview

A span processor that queues spans in memory and exports them all in one batch when force_flush is called. This avoids HTTP requests during test execution.

Instance Method Summary collapse

Constructor Details

#initialize(exporter) ⇒ SynchronousBatchSpanProcessor

Returns a new instance of SynchronousBatchSpanProcessor.



13
14
15
16
# File 'lib/mergify/rspec/synchronous_batch_span_processor.rb', line 13

def initialize(exporter)
  super
  @queue = []
end

Instance Method Details

#force_flush(timeout: nil) ⇒ Object

rubocop:disable Lint/UnusedMethodArgument

Raises:



24
25
26
27
28
29
30
31
# File 'lib/mergify/rspec/synchronous_batch_span_processor.rb', line 24

def force_flush(timeout: nil) # rubocop:disable Lint/UnusedMethodArgument
  spans = @queue.dup
  @queue.clear
  result = @span_exporter.export(spans)
  raise ExportError, 'Failed to export traces' unless result == OpenTelemetry::SDK::Trace::Export::SUCCESS

  OpenTelemetry::SDK::Trace::Export::SUCCESS
end

#on_finish(span) ⇒ Object



18
19
20
21
22
# File 'lib/mergify/rspec/synchronous_batch_span_processor.rb', line 18

def on_finish(span)
  return unless span.context.trace_flags.sampled?

  @queue << span.to_span_data
end