trallnag / prometheus-fastapi-instrumentator

Instrument your FastAPI with Prometheus metrics.
ISC License
929 stars 83 forks source link

feat: Relax type of get_route_name argument to HttpConnection #276

Closed pajowu closed 6 months ago

pajowu commented 9 months ago

What does this do?

This pr changes the type hint of get_route_name to accept a HttpConnection instead of a Request. All information get_route_name needs is already provided by the HttpConnection class, which Request is a subclass of. Changing this to HttpConnection allows also passing a WebSocket instead

Why do we need it?

This allows developers to use the get_route_name function for getting the name of websocket routes as well, which can be very useful for creating custom metrics, e.g. https://github.com/bugbakery/transcribee/pull/389/files#diff-82bbfd4c38c16c9ba393ea259a91bd7a73077f6edc59368d492fe172ac933625R39

Who is this for?

People who want to create own metrics for websocket routes.

codecov[bot] commented 6 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 95.68%. Comparing base (85f72b7) to head (ee2adf3).

:exclamation: Current head ee2adf3 differs from pull request most recent head 8ba359a. Consider uploading reports for the commit 8ba359a to get more accurate results

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #276 +/- ## ======================================= Coverage 95.68% 95.68% ======================================= Files 5 5 Lines 348 348 ======================================= Hits 333 333 Misses 15 15 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.