From a4204baec01ed4657444b578d72f92cb1066daaf Mon Sep 17 00:00:00 2001 From: pajowu Date: Mon, 20 Nov 2023 09:23:24 +0100 Subject: [PATCH 1/4] 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 --- src/prometheus_fastapi_instrumentator/routing.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/prometheus_fastapi_instrumentator/routing.py b/src/prometheus_fastapi_instrumentator/routing.py index 2c714d3..0725c0a 100644 --- a/src/prometheus_fastapi_instrumentator/routing.py +++ b/src/prometheus_fastapi_instrumentator/routing.py @@ -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 @@ -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 From d61b37a3bcb0cbe8f782e7324f04b540c66313b0 Mon Sep 17 00:00:00 2001 From: Tim Schwenke Date: Sun, 10 Mar 2024 12:12:10 +0100 Subject: [PATCH 2/4] fix: Fix capitalization of class --- src/prometheus_fastapi_instrumentator/routing.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/prometheus_fastapi_instrumentator/routing.py b/src/prometheus_fastapi_instrumentator/routing.py index 0725c0a..43d964f 100644 --- a/src/prometheus_fastapi_instrumentator/routing.py +++ b/src/prometheus_fastapi_instrumentator/routing.py @@ -39,7 +39,7 @@ from typing import List, Optional -from starlette.requests import HttpConnection +from starlette.requests import HTTPConnection from starlette.routing import Match, Mount, Route from starlette.types import Scope @@ -66,7 +66,7 @@ def _get_route_name( return None -def get_route_name(request: HttpConnection) -> Optional[str]: +def get_route_name(request: HTTPConnection) -> Optional[str]: """Gets route name for given request taking mounts into account.""" app = request.app From ee2adf33a447d938b7a3d3ae707ba605d3f5e848 Mon Sep 17 00:00:00 2001 From: Tim Schwenke Date: Sun, 10 Mar 2024 12:16:05 +0100 Subject: [PATCH 3/4] docs: Add entry to changelog --- CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5df36cc..9372baa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,14 @@ and adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0). ## Unreleased +### Changed + +- 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 change 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. From 8ba359a9f5e340722cc83099e88e3fe7b48a11bd Mon Sep 17 00:00:00 2001 From: Tim Schwenke Date: Sun, 10 Mar 2024 12:17:23 +0100 Subject: [PATCH 4/4] docs: Change type of change to feature --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9372baa..86f594e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,12 +7,12 @@ and adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0). ## Unreleased -### Changed +### 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 change in + proposing and implementing this feature in [#276](https://github.com/trallnag/prometheus-fastapi-instrumentator/pull/276). ### Removed