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

Check exceptions in force_flush too #2671

Merged
merged 2 commits into from
May 8, 2022
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -373,12 +373,35 @@ def __init__(
def force_flush(self, timeout_millis: float = 10_000) -> bool:
deadline_ns = _time_ns() + timeout_millis * 10**6

metric_reader_error = {}

for metric_reader in self._sdk_config.metric_readers:
current_ts = _time_ns()
if current_ts >= deadline_ns:
raise Exception("Timed out while flushing metric readers")
metric_reader.collect(
timeout_millis=(deadline_ns - current_ts) / 10**6
try:
if current_ts >= deadline_ns:
raise Exception("Timed out while flushing metric readers")
metric_reader.collect(
timeout_millis=(deadline_ns - current_ts) / 10**6
)

# pylint: disable=broad-except
except Exception as error:

metric_reader_error[metric_reader] = error

if metric_reader_error:

metric_reader_error_string = "\n".join(
[
f"{metric_reader.__class__.__name__}: {repr(error)}"
for metric_reader, error in metric_reader_error.items()
]
)

raise Exception(
"MeterProvider.force_flush failed because the following "
"metric readers failed during collect:\n"
f"{metric_reader_error_string}"
)
return True

Expand Down