prometheus-fastapi-instrumentator
prometheus-fastapi-instrumentator copied to clipboard
Add async instrumentation support
@trallnag should this be merged?
Async support would be great
Is this still relevant? From what I understand the new middleware implementation is async. I did not implement this, so I can't say for sure. In addition I know almost nothing about async Python.
https://github.com/trallnag/prometheus-fastapi-instrumentator/pull/139
We use this branch at work, so it would be awesome to have it on master :)
Edit: I'll try to read through the changes to make sure
Codecov Report
Merging #61 (b8491ab) into master (e1b2391) will increase coverage by
0.14%
. The diff coverage is100.00%
.
@@ Coverage Diff @@
## master #61 +/- ##
==========================================
+ Coverage 93.60% 93.75% +0.14%
==========================================
Files 5 5
Lines 297 304 +7
==========================================
+ Hits 278 285 +7
Misses 19 19
Impacted Files | Coverage Δ | |
---|---|---|
...ometheus_fastapi_instrumentator/instrumentation.py | 95.52% <100.00%> (+0.28%) |
:arrow_up: |
...rc/prometheus_fastapi_instrumentator/middleware.py | 95.23% <100.00%> (+0.17%) |
:arrow_up: |
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.
I managed to rebase your enhancement into the new middleware. I don't have any tests yet. Can you add examples on how you use async_instrumentation
? Of course only if it is still relevant for you.
I will go ahead and merge it into master
regardless because the changes don't interfere in any way with existing code.
... Can you add examples on how you use
async_instrumentation
?
Hi, we use this feature actively.
The use-case is exactly as with the non-async case:
sync_metric = Info("sync_metric", "Documentation")
async_metric = Info("async_metric", "Documentation")
def sync_function(_: InstInfo) -> None:
value = sync_metric_getter()
sync_metric.info({"type": value})
async def async_function(_: InstInfo) -> None:
value = await async_metric_getter()
async_metric.info({"type": value})
instrumentator = Instrumentator()
instrumentator.add(sync_function)
instrumentator.add(async_function)
This just adds the option of using async def
functions.
@Skeen, thanks for the example. Adapted it into a unit test
@Skeen, thanks for the example. Adapted it into a unit test
You're awesome, thank you for the work that you do!
What @Skeen said - Thank you!
One last request, would it be possible to get a release with these changes sometime in the near future, @trallnag?
@AndreasPB, I'll release it already this weekend