Skip to content

Commit b13bb71

Browse files
committed
Limit Spans count to BatchConfig::max_queue_size
1 parent ceb8172 commit b13bb71

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

opentelemetry-sdk/src/trace/span_processor_with_async_runtime.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,14 +234,21 @@ impl<E: SpanExporter, R: RuntimeChannel> BatchSpanProcessorInternal<E, R> {
234234
match message {
235235
// Span has finished, add to buffer of pending spans.
236236
BatchMessage::ExportSpan(span) => {
237-
if self.spans.len() == self.config.max_export_batch_size {
237+
if self.spans.len() == self.config.max_queue_size {
238238
// Replace the oldest span with the new span to avoid suspending messages
239239
// processing.
240240
self.spans.pop_front();
241+
242+
otel_warn!(
243+
name: "BatchSpanProcessor.Export.Error",
244+
dropped_spans = 1,
245+
max_queue_size = self.config.max_queue_size,
246+
message = "Spans were dropped due to a full queue / slow export. The count represents the total count of span records dropped in the lifetime of the BatchSpanProcessor. Consider increasing the queue size and/or decrease delay between intervals."
247+
);
241248
}
242249
self.spans.push_back(span);
243250

244-
if self.spans.len() == self.config.max_export_batch_size {
251+
if self.spans.len() >= self.config.max_export_batch_size {
245252
// If concurrent exports are saturated, wait for one to complete.
246253
if !self.export_tasks.is_empty()
247254
&& self.export_tasks.len() == self.config.max_concurrent_exports
@@ -314,7 +321,8 @@ impl<E: SpanExporter, R: RuntimeChannel> BatchSpanProcessorInternal<E, R> {
314321
return Ok(());
315322
}
316323

317-
let export = self.exporter.export(self.spans.drain(..).collect());
324+
let count = self.spans.len().min(self.config.max_export_batch_size);
325+
let export = self.exporter.export(self.spans.drain(..count).collect());
318326
let timeout = self.runtime.delay(self.config.max_export_timeout);
319327
let time_out = self.config.max_export_timeout;
320328

0 commit comments

Comments
 (0)