perf: FastAPI OTel middleware and /metrics endpoint #209
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Implement
src/perf/middleware.pyfor API observability.Tasks
instrument(app)— one-liner that addsFastAPIInstrumentor(auto-spans for all routes)/metricsendpoint for Prometheus scrapeserver.py: callperf.init()+perf.middleware.instrument(app)Complete.
Created:
src/perf/middleware.pyinstrument(app)— wraps FastAPIInstrumentor, no-op when disabled or OTel missingModified:
src/api/server.pyperf.init()+perf.middleware.instrument(app)withtry/except ImportErrorTests: 2 in
test_integration.pyinstrument()is safe no-op when disabledapi.server.appimports cleanly with perf wiring✅ All passing, lint clean.