Skip to content

Commit b299c7b

Browse files
committed
Add timeout millis param to export.
1 parent c40c9bf commit b299c7b

File tree

4 files changed

+24
-5
lines changed

4 files changed

+24
-5
lines changed

exporter/opentelemetry-exporter-otlp-proto-grpc/tests/test_otlp_trace_exporter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
import os
1818
from unittest import TestCase
19-
from unittest.mock import Mock, PropertyMock, patch, ANY
19+
from unittest.mock import ANY, Mock, PropertyMock, patch
2020

2121
from grpc import ChannelCredentials, Compression
2222

opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/export/__init__.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,14 @@ class LogExporter(abc.ABC):
7272
"""
7373

7474
@abc.abstractmethod
75-
def export(self, batch: Sequence[LogData]):
75+
def export(
76+
self, batch: Sequence[LogData], timeout_millis: Optional[int] = None
77+
):
7678
"""Exports a batch of logs.
7779
7880
Args:
79-
batch: The list of `LogData` objects to be exported
81+
batch: The list of `LogData` objects to be exported.
82+
timeout_millis: Optional milliseconds until Export should timeout if it hasn't succeded.
8083
8184
Returns:
8285
The result of the export
@@ -89,6 +92,13 @@ def shutdown(self):
8992
Called when the SDK is shut down.
9093
"""
9194

95+
@abc.abstractmethod
96+
def force_flush(self, timeout_millis: int = 30000) -> bool:
97+
"""Hint to ensure that the export of any spans the exporter has received
98+
prior to the call to ForceFlush SHOULD be completed as soon as possible, preferably
99+
before returning from this method.
100+
"""
101+
92102

93103
class ConsoleLogExporter(LogExporter):
94104
"""Implementation of :class:`LogExporter` that prints log records to the
@@ -107,6 +117,7 @@ def __init__(
107117
self.out = out
108118
self.formatter = formatter
109119

120+
# pylint: disable=arguments-differ
110121
def export(self, batch: Sequence[LogData]):
111122
for data in batch:
112123
self.out.write(self.formatter(data.log_record))

opentelemetry-sdk/src/opentelemetry/sdk/_logs/_internal/export/in_memory_log_exporter.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ def get_finished_logs(self) -> typing.Tuple[LogData, ...]:
4040
with self._lock:
4141
return tuple(self._logs)
4242

43+
# pylint: disable=arguments-differ
4344
def export(self, batch: typing.Sequence[LogData]) -> LogExportResult:
4445
if self._stopped:
4546
return LogExportResult.FAILURE

opentelemetry-sdk/src/opentelemetry/sdk/trace/export/__init__.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# limitations under the License.
1414
from __future__ import annotations
1515

16+
import abc
1617
import collections
1718
import logging
1819
import os
@@ -56,7 +57,7 @@ class SpanExportResult(Enum):
5657
FAILURE = 1
5758

5859

59-
class SpanExporter:
60+
class SpanExporter(abc.ABC):
6061
"""Interface for exporting spans.
6162
6263
Interface to be implemented by services that want to export spans recorded
@@ -66,24 +67,30 @@ class SpanExporter:
6667
`SimpleSpanProcessor` or a `BatchSpanProcessor`.
6768
"""
6869

70+
@abc.abstractmethod
6971
def export(
70-
self, spans: typing.Sequence[ReadableSpan]
72+
self,
73+
spans: typing.Sequence[ReadableSpan],
74+
timeout_millis: typing.Optional[int] = None,
7175
) -> "SpanExportResult":
7276
"""Exports a batch of telemetry data.
7377
7478
Args:
7579
spans: The list of `opentelemetry.trace.Span` objects to be exported
80+
timeout_millis: Optional milliseconds until Export should timeout if it hasn't succeded.
7681
7782
Returns:
7883
The result of the export
7984
"""
8085

86+
@abc.abstractmethod
8187
def shutdown(self) -> None:
8288
"""Shuts down the exporter.
8389
8490
Called when the SDK is shut down.
8591
"""
8692

93+
@abc.abstractmethod
8794
def force_flush(self, timeout_millis: int = 30000) -> bool:
8895
"""Hint to ensure that the export of any spans the exporter has received
8996
prior to the call to ForceFlush SHOULD be completed as soon as possible, preferably

0 commit comments

Comments
 (0)