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

Metrics endpoint described in openapi as returning json response #163

Open
avihaibd opened this issue Jul 6, 2022 · 2 comments
Open

Metrics endpoint described in openapi as returning json response #163

avihaibd opened this issue Jul 6, 2022 · 2 comments

Comments

@avihaibd
Copy link

avihaibd commented Jul 6, 2022

Default behavior when using documentation will show the /metrics endpoint in open-api autogenerated page as returning application/json

instrumentator.instrument(app).expose(app)

Result:

image

This can be resolved by using:

from starlette.responses import PlainTextResponse
instrumentator.instrument(app).expose(app, response_class=PlainTextResponse)

Another way of doint that would be:

from starlette.responses import Response
class PrometheusResponse(Response):
    media_type = prometheus_client.CONTENT_TYPE_LATEST

instrumentator.instrument(app).expose(app, response_class=PrometheusResponse)

Probably there are more ways to resolve, but I suggest that this would at least be included in docs.

@letmerecall
Copy link

letmerecall commented Jul 14, 2022

Any idea on how we can customize the Example Value?

@letmerecall
Copy link

letmerecall commented Jul 20, 2022

Any idea on how we can customize the Example Value?

Thanks, doing this for custom examples.

instrumentator.instrument(app).expose(
    app,
    response_class= PlainTextResponse,
    responses=
    {
        200: {
            "content":
                {
                    "text/plain": {
                        "example": '# Your sample response\n'
                                   '# Goes here'
                    },
                },
        },
    }
)

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

No branches or pull requests

2 participants