autometrics-dev / autometrics-py

Easily add metrics to your code that actually help you spot and debug issues in production. Built on Prometheus and OpenTelemetry.
https://autometrics.dev
Apache License 2.0
214 stars 7 forks source link

autometrics doesn't pick up fastapi routes/handlers #7

Closed mies closed 1 year ago

mies commented 1 year ago

I'm working on a fastapi sample app and have the folowing simple code:

from typing import Union

from fastapi import FastAPI
from autometrics.autometrics import autometrics
from prometheus_client import start_http_server

app = FastAPI()

@autometrics
@app.get("/")
async def read_root():
    do_something()
    return {"Hello": "World"}

start_http_server(8080)

# looking up this function in prometheus works
@autometrics
def do_something():
    print("done")

In this case do_something does get picked up by prometheus (running on 9090) but read_root does not. I don't know if its the chaining/order of the decorators. Changing the order of the decorators in the read_root actually breaks the handler.

v-aparna commented 1 year ago

This is resolved in the latest version of autometrics, pr