Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add force flush method to metric exporter #2852

Merged
merged 2 commits into from
Aug 2, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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:
ocelotl marked this conversation as resolved.
Show resolved Hide resolved
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