PeriodicExportingMetricReader discards its shutdown timeout - #5575
Open
dwin-gharibi wants to merge 2 commits into
Open
PeriodicExportingMetricReader discards its shutdown timeout#5575dwin-gharibi wants to merge 2 commits into
dwin-gharibi wants to merge 2 commits into
Conversation
Every MetricExporter.shutdown signature is shutdown(self, timeout_millis=30_000, **kwargs), so a budget passed under any other keyword lands in **kwargs and the exporter silently falls back to its own 30s default. Assert the exporter receives the remaining budget as timeout_millis, that nothing is swallowed into **kwargs, that the default is not used, and that an already-exhausted budget clamps at zero rather than going negative. These tests fail against the current implementation.
PeriodicExportingMetricReader.shutdown computed the time remaining after joining the ticker thread and passed it as `timeout=`. Every MetricExporter.shutdown is declared as `shutdown(self, timeout_millis=30_000, **kwargs)`, so the value was absorbed by **kwargs and discarded, and the exporter fell back to its own 30 second default. A caller asking for a 200ms shutdown could therefore block for 30s. The force_flush call three lines below already uses `timeout_millis=`, which is what makes this a slip rather than a decision. Also clamp at zero: joining the ticker thread can consume the whole budget, which would otherwise hand the exporter a negative timeout.
Pull request dashboard statusWaiting on reviewers · refreshed 2026-08-23 17:06 UTC Review the latest changes. Status above doesn't look right?
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #5574.
Description
PeriodicExportingMetricReader.shutdownworks out how much of the caller's budget is left after joining the ticker thread, then passes it to the exporter astimeout=. EveryMetricExporter.shutdownis declared asshutdown(self, timeout_millis=30_000, **kwargs), so the value is absorbed by**kwargsand discarded, and the exporter falls back to its own 30 second default.The
force_flushcall three lines below correctly usestimeout_millis=, which is what marks this as a slip rather than a deliberate choice.Root cause
opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/export/__init__.py:541. The keyword istimeout=where the exporter protocol declarestimeout_millis=.Approach
Rename the keyword to
timeout_millis, and clamp the computed value at zero. The clamp is not cosmetic: joining the ticker thread on the preceding line can consume the entire budget, which would otherwise hand the exporter a negative timeout - a case the new tests cover explicitly.Files changed
opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/export/__init__.pyopentelemetry-sdk/tests/metrics/test_periodic_exporting_metric_reader.py.changelog/5564.fixedTesting
Four tests drive
MeterProvider.shutdownwith a recording exporter and assert the exporter receives the budget astimeout_millis, that**kwargsis empty, and that the exporter's own 30s default is not used.The clamp test drives
reader.shutdown(timeout_millis=0)directly, becauseMeterProvider.shutdownenforces its own deadline first and would never reach the reader.Result: 859 passed in
opentelemetry-sdk(855 baseline plus 4 new).Risk / compatibility
Exporters now receive the timeout they were always meant to receive. An exporter that genuinely uses its budget will return sooner than before, which is the point; an exporter that ignores
timeout_millisis unaffected. No public signature changes.