Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTTPStatus.NOT_FOUND results in status "Hxx" when grouping (with fix) #190

Closed
Leem0sh opened this issue Oct 5, 2022 · 1 comment · Fixed by #192
Closed

HTTPStatus.NOT_FOUND results in status "Hxx" when grouping (with fix) #190

Leem0sh opened this issue Oct 5, 2022 · 1 comment · Fixed by #192

Comments

@Leem0sh
Copy link

Leem0sh commented Oct 5, 2022

Hello,

just noticed a bug where any "non-numeric" status code for example

from http import HTTPStatus
from starlette.responses import JSONResponse


@router.post(...)
def f():
    ...
    return JSONResponse(status_code=HTTPStatus.NOT_FOUND, detail="Item not found")

results in

http_requests_total{handler="/myhandler",method="POST",status="Hxx"} 3.0

Easy fix in my code is to do int(HTTPStatus.NOT_FOUND).

Or you can probably fix it in https://github.com/trallnag/prometheus-fastapi-instrumentator/blob/master/src/prometheus_fastapi_instrumentator/middleware.py#L117

status = str(int(status))[0] + "xx"

?

@Leem0sh Leem0sh changed the title HTTPStatus.NOT_FOUND results in status "Hxx" when grouping HTTPStatus.NOT_FOUND results in status "Hxx" when grouping (with fix) Oct 5, 2022
@nikstuckenbrock
Copy link
Contributor

I've created the PR #192 to fix this issue.

@trallnag trallnag linked a pull request Feb 22, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants