Taking inspiration from the way Strawberry handles integrations with common frameworks.
For instance, they have a package called strawberry-graphql[fastapi], which allows you to import a GraphQLRouter, which you can then use directly with FastAPI as follows (docs here):
I could imagine something similar for autometrics-py, which allows you to do the following
import strawberry
from fastapi import FastAPI
# NOTE - you'll need to `pip install 'autometrics[fastapi]` to use `MetricsRouter`
from autometrics.fastapi import MetricsRouter
metrics_app = MetricsRouter()
app = FastAPI()
app.include_router(metrics_app, prefix="/metrics")
Effectively, this MetricsRouter would be sugar for
from prometheus_client import generate_latest
# Set up a metrics endpoint for Prometheus to scrape
# `generate_latest` returns metrics data in the Prometheus text format
@app.get("/metrics")
def metrics():
return Response(generate_latest())
Taking inspiration from the way Strawberry handles integrations with common frameworks.
For instance, they have a package called
strawberry-graphql[fastapi]
, which allows you to import aGraphQLRouter
, which you can then use directly with FastAPI as follows (docs here):I could imagine something similar for autometrics-py, which allows you to do the following
Effectively, this
MetricsRouter
would be sugar for