Repository navigation
Support async functions in metric decorators - #1242
Open
siddham-jain wants to merge 1 commit into
Open
siddham-jain wants to merge 1 commit into
siddham-jain wants to merge 1 commit into
Conversation
Signed-off-by: Siddham Jain <siddhamjain224@gmail.com>
This branch has not been deployed
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.
@csmarchbanks
Fixes #535.
Decorating an
async deffunction withHistogram.time(),Summary.time(),Gauge.time(),Counter.count_exceptions()orGauge.track_inprogress()currently wraps only the creation of the coroutine, not its execution. So the decorators silently record wrong data, e.g. a FastAPI endpoint that awaits for 100ms is observed as ~1µs, raised exceptions are not counted, and the in-progress gauge is back to 0 before the body runs. The wrapper is also no longer a coroutine function, soinspect.iscoroutinefunction()returnsFalsefor it.Changes:
decorator4.1 into the bundleddecorator.py:FunctionMaker.creategenerates anasync defwrapper withreturn awaitwhen the caller is a coroutine function (andmakeusesDEF.searchso that template parses). Signatures stay preserved as before.context_managers.pyuses an async caller for coroutine functions, so thewithblock spans the awaited call. Sync functions take the same path as before.async deffunctions, including overlapping calls viaasyncio.gather, plus a note in the instrumenting docs.This picks up the direction discussed in #535 now that Python 2 is gone, and supersedes the stalled #767, whose tests cover the same cases.