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/5294.added
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
`opentelemetry-sdk`: add `force_flush` method to `LogRecordExporter` ABC
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,21 @@ def shutdown(self):
Called when the SDK is shut down.
"""

@abc.abstractmethod
def force_flush(self, timeout_millis: float = 10_000) -> bool:
"""Hint to ensure that the export of any ``ReadableLogRecord`` objects
the exporter has received prior to the call to ``force_flush`` SHOULD be
completed as soon as possible, preferably before returning from this method.

Args:
timeout_millis: The maximum amount of time to wait for the flush to
complete, in milliseconds.

Returns:
``True`` if the flush completed successfully within the timeout,
``False`` otherwise.
"""


@deprecated(
"Use LogRecordExporter. Since logs are not stable yet this WILL be removed in future releases."
Expand Down Expand Up @@ -154,6 +169,9 @@ def export(self, batch: Sequence[ReadableLogRecord]):
def shutdown(self):
pass

def force_flush(self, timeout_millis: float = 10_000) -> bool:
return True


@deprecated(
"Use ConsoleLogRecordExporter. Since logs are not stable yet this WILL be removed in future releases."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ def export(
def shutdown(self) -> None:
self._stopped = True

def force_flush(self, timeout_millis: float = 10_000) -> bool:
return True


@deprecated(
"Use InMemoryLogRecordExporter. Since logs are not stable yet this WILL be removed in future releases."
Expand Down
13 changes: 13 additions & 0 deletions opentelemetry-sdk/tests/logs/test_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ class Exporter(LogRecordExporter):
def shutdown(self):
pass

def force_flush(self, timeout_millis: float = 10_000) -> bool:
return True

def export(self, batch: Sequence[ReadableLogRecord]):
logger = logging.getLogger("any logger..")
logger.warning("Something happened.")
Expand Down Expand Up @@ -929,3 +932,13 @@ def formatter(record): # pylint: disable=unused-argument
exporter.export([EMPTY_LOG])

mock_stdout.write.assert_called_once_with(mock_record_str)

def test_force_flush(self):
exporter = ConsoleLogRecordExporter()
self.assertTrue(exporter.force_flush())


class TestInMemoryLogRecordExporter(unittest.TestCase):
def test_force_flush(self):
exporter = InMemoryLogRecordExporter()
self.assertTrue(exporter.force_flush())
3 changes: 3 additions & 0 deletions opentelemetry-sdk/tests/test_configurator.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,9 @@ def export(self, batch):
def shutdown(self):
pass

def force_flush(self, timeout_millis: float = 10_000) -> bool:
return True


class CustomSampler(Sampler):
def __init__(self) -> None:
Expand Down
Loading