Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/agents/tracing/processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,9 @@ def __init__(
schedule_delay: The delay between checks for new spans to export.
export_trigger_ratio: The ratio of the queue size at which we will trigger an export.
"""
if max_batch_size < 1:
raise ValueError("max_batch_size must be at least 1")

self._exporter = exporter
self._queue: queue.Queue[Trace | Span[Any]] = queue.Queue(maxsize=max_queue_size)
self._max_queue_size = max_queue_size
Expand Down
17 changes: 17 additions & 0 deletions tests/test_trace_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,23 @@ def test_batch_trace_processor_on_trace_start(mocked_exporter):
processor.shutdown()


def test_batch_trace_processor_rejects_zero_max_batch_size(mocked_exporter):
with pytest.raises(ValueError, match="max_batch_size must be at least 1"):
BatchTraceProcessor(exporter=mocked_exporter, max_batch_size=0)


def test_batch_trace_processor_force_flush_exports_every_queued_item(mocked_exporter):
processor = BatchTraceProcessor(exporter=mocked_exporter, max_batch_size=1)
processor.on_trace_start(get_trace(processor))
processor.on_span_end(get_span(processor))

processor.force_flush()

assert mocked_exporter.export.call_count == 2
assert processor._queue.empty()
processor.shutdown()


def test_batch_trace_processor_on_span_end(mocked_exporter):
processor = BatchTraceProcessor(exporter=mocked_exporter, schedule_delay=0.1)
test_span = get_span(processor)
Expand Down
Loading