This looks cool. My concern about adding such a middleware to the API routes is the potential performance hit. Assuming this middleware would call your APIs to track metrics, wouldn't it degrade the performance of the existing system by consuming some CPU power?
Valid concern that I tried to specifically address in how the SDKs are implemented! The middleware part is actually super lightweight. It only captures relevant metrics from the request and response and stores them in memory. Further processing and sending to Apitally happens asynchronously in the background, in regular intervals. That way the performance impact on request handling is very minimal.
Anecdotally, I noticed zero increase in CPU usage when I added the Apitally SDK to a FastAPI app that handles ~100 req/s. In comparison, adding OpenTelemetry was very noticeable, at least doubling the CPU usage.