Our backend services are mostly built with FastAPI, and I'm looking for open-source runtime coverage instrumentation for Python. Ideally, it would show which lines of code were executed by real production traffic over something like the last 30 days. I've seen solutions for this in Go and Java, but I'm not sure what the best Python options are. I'm specifically interested in runtime line coverage, rather than only request tracing or performance profiling.
2 Answers
If you want production observability rather than strict coverage data, Pydantic Logfire is worth considering. It integrates nicely with Python and FastAPI applications and can help reveal what your services are actually doing in production.
coverage.py is the standard tool to investigate, but it’s primarily designed for test-time coverage. Running it continuously across production traffic for 30 days could add overhead and produce a lot of data, so you’d need to evaluate the performance and storage impact carefully.

I’ve had a good experience with Logfire as well. It was straightforward to integrate and gave us useful visibility into the application’s runtime behavior.