Skip to content

Commit

Permalink
feat: Relax type of get_route_name argument to HttpConnection (#276)
Browse files Browse the repository at this point in the history
* Relax type of get_route_name argument to HttpConnection

All information required is already provided by the HttpConnection class, which Request is a subclass of. Changing this to HttpConnection allows also passing a WebSocket instead

* fix: Fix capitalization of class

* docs: Add entry to changelog

* docs: Change type of change to feature

---------

Co-authored-by: Tim Schwenke <[email protected]>
  • Loading branch information
pajowu and trallnag authored Mar 10, 2024
1 parent 85f72b7 commit 885c80c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ and adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0).

## Unreleased

### Added

- Relaxed type of `get_route_name` argument to `HTTPConnection`. This allows
developers to use the `get_route_name` function for getting the name of
websocket routes as well. Thanks to [@pajowu](https://github.com/pajowu) for
proposing and implementing this feature in
[#276](https://github.com/trallnag/prometheus-fastapi-instrumentator/pull/276).

### Removed

- **BREAKING:** Dropped support for Python 3.7 which is has reached end-of-life.
Expand Down
4 changes: 2 additions & 2 deletions src/prometheus_fastapi_instrumentator/routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

from typing import List, Optional

from starlette.requests import Request
from starlette.requests import HTTPConnection
from starlette.routing import Match, Mount, Route
from starlette.types import Scope

Expand All @@ -66,7 +66,7 @@ def _get_route_name(
return None


def get_route_name(request: Request) -> Optional[str]:
def get_route_name(request: HTTPConnection) -> Optional[str]:
"""Gets route name for given request taking mounts into account."""

app = request.app
Expand Down

0 comments on commit 885c80c

Please sign in to comment.