Skip to content

Commit c6d7b9f

Browse files
authored
Add force flush method to metric exporter (#2852)
1 parent 43288ca commit c6d7b9f

File tree

6 files changed

+24
-0
lines changed

6 files changed

+24
-0
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
- Add `force_flush` method to metrics exporter
11+
([#2852](https://github.com/open-telemetry/opentelemetry-python/pull/2852))
1012
- Change tracing to use `Resource.to_json()`
1113
([#2784](https://github.com/open-telemetry/opentelemetry-python/pull/2784))
1214
- Fix get_log_emitter instrumenting_module_version args typo

exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/metric_exporter/__init__.py

+3
Original file line numberDiff line numberDiff line change
@@ -210,3 +210,6 @@ def shutdown(self, timeout_millis: float = 30_000, **kwargs) -> None:
210210
@property
211211
def _exporting(self) -> str:
212212
return "metrics"
213+
214+
def force_flush(self, timeout_millis: float = 10_000) -> bool:
215+
return True

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

+10
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,13 @@ def export(
9191
The result of the export
9292
"""
9393

94+
@abstractmethod
95+
def force_flush(self, timeout_millis: float = 10_000) -> bool:
96+
"""
97+
Ensure that export of any metrics currently received by the exporter
98+
are completed as soon as possible.
99+
"""
100+
94101
@abstractmethod
95102
def shutdown(self, timeout_millis: float = 30_000, **kwargs) -> None:
96103
"""Shuts down the exporter.
@@ -131,6 +138,9 @@ def export(
131138
def shutdown(self, timeout_millis: float = 30_000, **kwargs) -> None:
132139
pass
133140

141+
def force_flush(self, timeout_millis: float = 10_000) -> bool:
142+
return True
143+
134144

135145
class MetricReader(ABC):
136146
"""

opentelemetry-sdk/tests/metrics/test_backward_compat.py

+3
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ def export(
5353
def shutdown(self, timeout_millis: float = 30_000, **kwargs) -> None:
5454
pass
5555

56+
def force_flush(self, timeout_millis: float = 10_000) -> bool:
57+
return True
58+
5659

5760
class OrigMetricReader(MetricReader):
5861
def _receive_metrics(

opentelemetry-sdk/tests/metrics/test_metrics.py

+3
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,9 @@ def export(
445445
def shutdown(self, timeout_millis: float = 30_000, **kwargs) -> None:
446446
pass
447447

448+
def force_flush(self, timeout_millis: float = 10_000) -> bool:
449+
return True
450+
448451

449452
class TestDuplicateInstrumentAggregateData(TestCase):
450453
def test_duplicate_instrument_aggregate_data(self):

opentelemetry-sdk/tests/metrics/test_periodic_exporting_metric_reader.py

+3
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ def export(
5050
def shutdown(self, timeout_millis: float = 30_000, **kwargs) -> None:
5151
self._shutdown = True
5252

53+
def force_flush(self, timeout_millis: float = 10_000) -> bool:
54+
return True
55+
5356

5457
metrics_list = [
5558
Metric(

0 commit comments

Comments
 (0)