mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
fix(fastapi): check for prometheus info.response
When this is unchecked, exceptions cause the resulting stack trace to be oblivious to the original exception thrown. This commit changes that behavior so that metrics are created only when info.response exists. Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
parent
8788f99005
commit
0da11f068b
1 changed files with 6 additions and 4 deletions
|
@ -79,9 +79,10 @@ def http_requests_total() -> Callable[[Info], None]:
|
|||
|
||||
method = scope.get("method")
|
||||
path = get_matching_route_path(base_scope, scope.get("router").routes)
|
||||
status = str(int(info.response.status_code))[:1] + "xx"
|
||||
|
||||
metric.labels(method=method, path=path, status=status).inc()
|
||||
if info.response:
|
||||
status = str(int(info.response.status_code))[:1] + "xx"
|
||||
metric.labels(method=method, path=path, status=status).inc()
|
||||
|
||||
return instrumentation
|
||||
|
||||
|
@ -95,7 +96,8 @@ def http_api_requests_total() -> Callable[[Info], None]:
|
|||
def instrumentation(info: Info) -> None:
|
||||
if info.request.url.path.rstrip("/") == "/rpc":
|
||||
type = info.request.query_params.get("type", "None")
|
||||
status = str(info.response.status_code)[:1] + "xx"
|
||||
metric.labels(type=type, status=status).inc()
|
||||
if info.response:
|
||||
status = str(info.response.status_code)[:1] + "xx"
|
||||
metric.labels(type=type, status=status).inc()
|
||||
|
||||
return instrumentation
|
||||
|
|
Loading…
Add table
Reference in a new issue