sunhailin-Leo / fastapi_profiler

A FastAPI Middleware of https://github.com/joerick/pyinstrument to check your service performance.
MIT License
231 stars 13 forks source link

Question - I am not able to track every method under my fastapi endpoint #4

Closed sandeeppilania closed 3 years ago

sandeeppilania commented 3 years ago

In the logs i just see the framework level tracing, where as i want to know it for every method under the endpoint call. Am i missing something or is that the expected output. this is how as per your example i am adding to the fastapi middleware. app.add_middleware(PyInstrumentProfilerMiddleware)

kigawas commented 3 years ago

You don't need this library probably. Just use something like this:

from pyinstrument import Profiler

app = ...

@app.middleware("http")
async def __profiling(request: Request, call_next):
    p = Profiler()
    p.start()
    response: Response = await call_next(request)
    p.stop()
    p.print()
    return response
sunhailin-Leo commented 3 years ago

@kigawas use a middleware is more pythonic. 😄