From 6e837e0c023404e0a1c43dbdfde0826acb1f3381 Mon Sep 17 00:00:00 2001 From: Leonidas Spyropoulos Date: Mon, 21 Feb 2022 10:25:01 +0000 Subject: [PATCH] fix: always provide a path https://github.com/stephenhillier/starlette_exporter/commit/891efcd142da5a13f72ec9647ad0b8aca21075a8 --- aurweb/prometheus.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/aurweb/prometheus.py b/aurweb/prometheus.py index dae56320..73be3ef6 100644 --- a/aurweb/prometheus.py +++ b/aurweb/prometheus.py @@ -70,9 +70,17 @@ def http_requests_total() -> Callable[[Info], None]: if not (scope.get("endpoint", None) and scope.get("router", None)): return None + root_path = scope.get("root_path", "") + app = scope.get("app", {}) + + if hasattr(app, "root_path"): + app_root_path = getattr(app, "root_path") + if root_path.startswith(app_root_path): + root_path = root_path[len(app_root_path):] + base_scope = { "type": scope.get("type"), - "path": scope.get("root_path", "") + scope.get("path"), + "path": root_path + scope.get("path"), "path_params": scope.get("path_params", {}), "method": scope.get("method") }