Fix metrics collection timeout so slow observable callbacks raise MetricsTimeoutError - #5616
Open
henry3260 wants to merge 2 commits into
Open
Fix metrics collection timeout so slow observable callbacks raise MetricsTimeoutError#5616henry3260 wants to merge 2 commits into
henry3260 wants to merge 2 commits into
Conversation
…ricsTimeoutError _Asynchronous.callback is a generator function, so the previous deadline check ran before any user callback code executed and could never fire. Move the check after the measurement iteration, where the elapsed time is actually observable, and make the unit test's mock callback a generator to match the real instrument's lazy behavior.
Pull request dashboard statusWaiting on reviewers · refreshed 2026-09-05 10:19 UTC Review the latest changes. Status above doesn't look right?
|
|
|
henry3260
force-pushed
the
fix-metrics-collect-timeout
branch
from
September 3, 2026 16:21
880ad20 to
f8e87ab
Compare
ocelotl
approved these changes
Sep 4, 2026
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.
Description
_Asynchronous.callbackis a generator function, so calling it returns immediately without executing any user callback code. The deadline check inSynchronousMeasurementConsumer.collectran right after that call, before the loop that actually drives the callbacks, so it always observed ~0 elapsed time andtimeout_milliscould never raiseMetricsTimeoutError.Move the deadline check after the measurement iteration, where the elapsed time is actually observable. A single slow callback now raises
MetricsTimeoutErroronce it finishes, and remaining instruments are not invoked after the deadline passes. The existingtest_collect_timeoutonly passed because itsMockcallback slept at call time; it now uses a generator to match the real instrument's lazy behavior (it fails without the fix).Fixes # (issue)
Type of change
How Has This Been Tested?
test_collect_timeoutto use a generator callback like the real_Asynchronous.callback; it fails without the fix and passes with it.pytest opentelemetry-sdk/tests/metrics/test_measurement_consumer.py(9 passed)Does This PR Require a Contrib Repo Change?
Checklist: