Skip to content
Open
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
1 change: 1 addition & 0 deletions .changelog/5648.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
`opentelemetry-sdk`: add validation for export_timeout_millis <= 0 in BatchSpanProcessor
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,12 @@ def __init__(
if export_timeout_millis is None:
export_timeout_millis = BatchSpanProcessor._default_export_timeout_millis()

BatchSpanProcessor._validate_arguments(max_queue_size, schedule_delay_millis, max_export_batch_size)
BatchSpanProcessor._validate_arguments(
max_queue_size,
schedule_delay_millis,
max_export_batch_size,
export_timeout_millis,
)

self._batch_processor = BatchProcessor(
span_exporter,
Expand Down Expand Up @@ -274,7 +279,12 @@ def _default_export_timeout_millis():
return _DEFAULT_EXPORT_TIMEOUT_MILLIS

@staticmethod
def _validate_arguments(max_queue_size, schedule_delay_millis, max_export_batch_size):
def _validate_arguments(
max_queue_size,
schedule_delay_millis,
max_export_batch_size,
export_timeout_millis=None,
):
if max_queue_size <= 0:
raise ValueError("max_queue_size must be a positive integer.")

Expand All @@ -287,6 +297,9 @@ def _validate_arguments(max_queue_size, schedule_delay_millis, max_export_batch_
if max_export_batch_size > max_queue_size:
raise ValueError("max_export_batch_size must be less than or equal to max_queue_size.")

if export_timeout_millis is not None and export_timeout_millis <= 0:
raise ValueError("export_timeout_millis must be positive.")


class ConsoleSpanExporter(SpanExporter):
"""Implementation of :class:`SpanExporter` that prints spans to the
Expand Down
10 changes: 10 additions & 0 deletions opentelemetry-sdk/tests/trace/export/test_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,16 @@ def test_args_env_var(self):
self.assertEqual(batch_span_processor._batch_processor._export_timeout_millis, 4)
batch_span_processor.shutdown()

def test_invalid_export_timeout_millis(self):
with self.assertRaises(ValueError):
export.BatchSpanProcessor(
MySpanExporter(destination=[]), export_timeout_millis=0
)
with self.assertRaises(ValueError):
export.BatchSpanProcessor(
MySpanExporter(destination=[]), export_timeout_millis=-500
)

def test_args_env_var_defaults(self):
batch_span_processor = export.BatchSpanProcessor(MySpanExporter(destination=[]))

Expand Down
Loading