Skip to content

Commit

Permalink
Add force flush method to metric exporter
Browse files Browse the repository at this point in the history
Fixes #2850
  • Loading branch information
ocelotl committed Aug 1, 2022
1 parent c9222bf commit 835c7dc
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

- Add `force_flush` method to metrics exporter
([#2852](https://github.com/open-telemetry/opentelemetry-python/pull/2852))
- Change tracing to use `Resource.to_json()`
([#2784](https://github.com/open-telemetry/opentelemetry-python/pull/2784))
- Fix get_log_emitter instrumenting_module_version args typo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,3 +210,6 @@ def shutdown(self, timeout_millis: float = 30_000, **kwargs) -> None:
@property
def _exporting(self) -> str:
return "metrics"

def force_flush(self, timeout_millis: float = 10_000) -> bool:
return True
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@ def export(
The result of the export
"""

@abstractmethod
def force_flush(self, timeout_millis: float = 10_000) -> bool:
"""
Ensure that export of any metrics currently received by the exporter
are completed as soon as possible.
"""

@abstractmethod
def shutdown(self, timeout_millis: float = 30_000, **kwargs) -> None:
"""Shuts down the exporter.
Expand Down Expand Up @@ -125,6 +132,9 @@ def export(
def shutdown(self, timeout_millis: float = 30_000, **kwargs) -> None:
pass

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


class MetricReader(ABC):
"""
Expand Down
3 changes: 3 additions & 0 deletions opentelemetry-sdk/tests/metrics/test_backward_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ def export(
def shutdown(self, timeout_millis: float = 30_000, **kwargs) -> None:
pass

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


class OrigMetricReader(MetricReader):
def _receive_metrics(
Expand Down
3 changes: 3 additions & 0 deletions opentelemetry-sdk/tests/metrics/test_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,9 @@ def export(
def shutdown(self, timeout_millis: float = 30_000, **kwargs) -> None:
pass

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


class TestDuplicateInstrumentAggregateData(TestCase):
def test_duplicate_instrument_aggregate_data(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ def export(
def shutdown(self, timeout_millis: float = 30_000, **kwargs) -> None:
self._shutdown = True

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


metrics_list = [
Metric(
Expand Down

0 comments on commit 835c7dc

Please sign in to comment.