lib/opentelemetry/sdk/trace/export/batch_span_processor.rb in opentelemetry-sdk-0.2.0 vs lib/opentelemetry/sdk/trace/export/batch_span_processor.rb in opentelemetry-sdk-0.3.0
- old
+ new
@@ -70,20 +70,37 @@
spans << span
@condition.signal if spans.size > max_queue_size / 2
end
end
+ # TODO: test this explicitly.
+ # Export all ended spans to the configured `Exporter` that have not yet
+ # been exported.
+ #
+ # This method should only be called in cases where it is absolutely
+ # necessary, such as when using some FaaS providers that may suspend
+ # the process after an invocation, but before the `Processor` exports
+ # the completed spans.
+ def force_flush
+ snapshot = lock { spans.shift(spans.size) }
+ until snapshot.empty?
+ batch = snapshot.shift(@batch_size).map!(&:to_span_data)
+ result_code = @exporter.export(batch)
+ report_result(result_code, batch)
+ end
+ end
+
# shuts the consumer thread down and flushes the current accumulated buffer
# will block until the thread is finished
def shutdown
lock do
@keep_running = false
@condition.signal
end
@thread.join
- flush
+ force_flush
@exporter.shutdown
end
private
@@ -120,18 +137,9 @@
FAILED_NOT_RETRYABLE
end
def report_result(result_code, batch)
OpenTelemetry.logger.error("Unable to export #{batch.size} spans") unless result_code == SUCCESS
- end
-
- def flush
- snapshot = lock { spans.shift(spans.size) }
- until snapshot.empty?
- batch = snapshot.shift(@batch_size).map!(&:to_span_data)
- result_code = @exporter.export(batch)
- report_result(result_code, batch)
- end
end
def fetch_batch
spans.shift(@batch_size).map!(&:to_span_data)
end