Skip to content

Commit 5fa8c23

Browse files
committed
Fix merging
1 parent f503053 commit 5fa8c23

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

opentelemetry-sdk/src/opentelemetry/sdk/_shared_internal/__init__.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ def emit(self, data: Telemetry) -> None:
182182
self._queue.appendleft(data)
183183
if len(self._queue) >= self._max_export_batch_size:
184184
self._worker_awaken.set()
185-
185+
186186
def shutdown(self, timeout_millis: int = 30000):
187187
if self._shutdown:
188188
return
@@ -209,8 +209,10 @@ def shutdown(self, timeout_millis: int = 30000):
209209
self._exporter.shutdown(timeout_millis=0) # type: ignore
210210
else:
211211
self._exporter.shutdown()
212-
# Worker thread should be finished at this point and return instantly.
213-
self._worker_thread.join()
212+
# Worker thread **should** be finished at this point, because we called shutdown on the exporter,
213+
# and set shutdown_is_occuring to prevent further export calls. It's possible that a single export
214+
# call is ongoing and the thread isn't finished. In this case we will return instead of waiting on
215+
# the thread to finish.
214216

215217
# TODO: Fix force flush so the timeout is used https://github.com/open-telemetry/opentelemetry-python/issues/4568.
216218
def force_flush(self, timeout_millis: Optional[int] = None) -> bool:

opentelemetry-sdk/tests/shared_internal/test_batch_processor.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,14 +239,15 @@ def test_shutdown_cancels_longrunning_export(self, batch_processor_class, teleme
239239

240240
def test_shutdown_allows_1_export_to_finish(self, batch_processor_class, telemetry, caplog):
241241
# This exporter throws an exception if it's export sleep cannot finish.
242+
dir(caplog)
242243
exporter = MockExporterForTesting(export_sleep=2)
243244
processor = batch_processor_class(
244245
exporter,
245246
max_queue_size=200,
246247
max_export_batch_size=1,
247248
schedule_delay_millis=30000,
248249
)
249-
# Max export batch size is 1, so 3 emit calls requires 3 separate calls to Export to clear the queue.
250+
# Max export batch size is 1, so 3 emit calls requires 3 separate calls (each block for 2 seconds) to Export to clear the queue.
250251
processor._batch_processor.emit(telemetry)
251252
processor._batch_processor.emit(telemetry)
252253
processor._batch_processor.emit(telemetry)

0 commit comments

Comments
 (0)