Is there an open-source way to measure Python code coverage from production traffic?

August 4, 2026 4 answers
Asked by MellowCedar42
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.

Answers

BriskWalnut63
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.
Reply to this answer
QuietMarble5
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.

AmberKite28: 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.

Reply to this answer
OrbitingLime7
OpenTelemetry has FastAPI instrumentation and is a good foundation for tracing requests through your services. It wonโ€™t directly provide line-by-line code coverage, but it can show which endpoints and execution paths production traffic is using without tying you to one observability vendor.
Reply to this answer
SilverMoss91
Grafana Pyroscope may be useful if profiling is close enough to what you need. It collects runtime profiles from Python and can show which parts of the application consume execution time. Keep in mind that profiling is different from exact line coverage: it tells you what was running and how often, not necessarily every line that executed.
Reply to this answer

Add your answer

Answers are reviewed before publication.

Related Discussions