lib/opentelemetry/sdk/trace/export/batch_span_processor.rb in opentelemetry-sdk-1.3.1 vs lib/opentelemetry/sdk/trace/export/batch_span_processor.rb in opentelemetry-sdk-1.3.2
- old
+ new
@@ -79,12 +79,12 @@
lock do
reset_on_fork
n = spans.size + 1 - max_queue_size
if n.positive?
- spans.shift(n)
- report_dropped_spans(n, reason: 'buffer-full')
+ dropped_spans = spans.shift(n)
+ report_dropped_spans(dropped_spans, reason: 'buffer-full', function: __method__.to_s)
end
spans << span
@condition.signal if spans.size > batch_size
end
end
@@ -120,12 +120,12 @@
# Unshift the remaining spans if we timed out. We drop excess spans from
# the snapshot because they're older than any spans in the spans buffer.
lock do
n = spans.size + snapshot.size - max_queue_size
if n.positive?
- snapshot.shift(n)
- report_dropped_spans(n, reason: 'buffer-full')
+ dropped_spans = snapshot.shift(n)
+ report_dropped_spans(dropped_spans, reason: 'buffer-full', function: __method__.to_s)
end
spans.unshift(snapshot) unless snapshot.empty?
@condition.signal if spans.size > max_queue_size / 2
end
end
@@ -144,12 +144,12 @@
@thread
end
thread&.join(timeout)
force_flush(timeout: OpenTelemetry::Common::Utilities.maybe_timeout(timeout, start_time))
- dropped_spans = lock { spans.size }
- report_dropped_spans(dropped_spans, reason: 'terminating') if dropped_spans.positive?
+ dropped_spans = lock { spans.shift(spans.length) }
+ report_dropped_spans(dropped_spans, reason: 'terminating') if dropped_spans.any?
@exporter.shutdown(timeout: OpenTelemetry::Common::Utilities.maybe_timeout(timeout, start_time))
end
private
@@ -198,15 +198,15 @@
@metrics_reporter.add_to_counter('otel.bsp.export.success')
@metrics_reporter.add_to_counter('otel.bsp.exported_spans', increment: batch.size)
else
OpenTelemetry.handle_error(exception: ExportError.new("Unable to export #{batch.size} spans"))
@metrics_reporter.add_to_counter('otel.bsp.export.failure')
- report_dropped_spans(batch.size, reason: 'export-failure')
+ report_dropped_spans(batch, reason: 'export-failure')
end
end
- def report_dropped_spans(count, reason:)
- @metrics_reporter.add_to_counter('otel.bsp.dropped_spans', increment: count, labels: { 'reason' => reason })
+ def report_dropped_spans(dropped_spans, reason:, function: nil)
+ @metrics_reporter.add_to_counter('otel.bsp.dropped_spans', increment: dropped_spans.size, labels: { 'reason' => reason, OpenTelemetry::SemanticConventions::Trace::CODE_FUNCTION => function }.compact)
end
def fetch_batch
spans.shift(@batch_size).map!(&:to_span_data)
end