Skip to content
Fallow home
All docs pages

Docs home

Runtime coverage

Merge data from a running app into fallow health, so that you see which functions never run and which run often.

Static analysis tells you which code can run. It cannot tell you which code your users run. Runtime coverage is data about the functions that ran in a deployed app with real traffic. Fallow merges it into the health report, so that you delete cold code on evidence and review changes to busy code with care.

npx fallow health --runtime-coverage ./coverage

What fallow finds

The demo project has an unused export, cancelOrder, that nothing imports. A static report cannot show a function that the app imports but never calls, so this example adds one to the demo: refundOrder in src/services/orders.ts, which src/index.ts calls only when the command line has --refund. The app then ran once without that flag, with V8 coverage on (NODE_V8_COVERAGE=./coverage), and fallow read the capture:

● Runtime coverage: cold code detected
  22 tracked, 17 hit, 5 unhit, 3 untracked (77.3% covered)
  based on 240 traces over 0 days (0 deployments)
  src/lib/format.ts:3 formatPercent [0 invocations, safe to delete]
  src/services/orders.ts:18 cancelOrder [0 invocations, safe to delete]
  src/utils/legacy-currency.ts:3 fromGuilders [untracked, safe to delete]
  src/utils/legacy-currency.ts:1 toGuilders [untracked, safe to delete]
  src/services/orders.ts:20 refundOrder [0 invocations, review required]
  src/math.test.ts:6 <arrow> [untracked, coverage unavailable]
  src/math.test.ts:5 <arrow> [untracked, coverage unavailable]
  src/utils/test-helpers.ts:1 makeAmountCases [untracked, coverage unavailable]


Coverage intelligence
  Verdict: high-confidence-delete
  src/lib/format.ts:3 formatPercent high-confidence-delete [static_unused, runtime_cold, no_test_path]
    Confirm ownership, then remove cold unused code in `src/lib/format.ts:formatPercent`
  src/services/orders.ts:18 cancelOrder high-confidence-delete [static_unused, runtime_cold, no_test_path]
    Confirm ownership, then remove cold unused code in `src/services/orders.ts:cancelOrder`
PartMeaning
cold code detectedThe verdict of the report: clean, cold-code-detected, hot-path-touched, license-expired-grace or unknown.
22 tracked, 17 hit, 5 unhitThe functions that the capture tracked, and how many of them ran.
based on 240 tracesThe number of calls in the capture. A small number gives a lower confidence.
[0 invocations, safe to delete]One function, its call count, and its verdict.
Coverage intelligenceFindings that combine the runtime coverage with the static analysis and the tests, for example coverage-intelligence-delete.

The rest of the report is the normal health report. A capture with more traffic also lists the hot paths: the functions with 100 calls or more (--min-invocations-hot). No function of the demo ran that often in one run.

How fallow decides

Each line in the report pairs two facts: the static result (does a reachable file use the function?) and the call count in the capture. From the two, fallow gives each function one verdict:

VerdictMeaning
safe_to_delete (rule)No reachable code uses the function, and it did not run. This is the strongest signal to delete.
review_required (rule)Reachable code uses the function, but it did not run. It can be an error path, a seasonal feature, or code that is really unused.
low_traffic (rule)The function ran, but its share of all calls is below the low-traffic threshold: 0.1 percent by default.
coverage_unavailable (rule)Fallow could not match the function to the capture. This is not a signal to delete.
activeThe function ran above the threshold. The report does not list it.
unknownFallow could not decide.

In the demo, nothing imports cancelOrder, and nothing uses formatPercent, so both get safe_to_delete. src/index.ts imports refundOrder, but the run never took the --refund path, so it gets review_required. The test file and its helper did not run in the app, so their functions get coverage_unavailable.

With --production, a function that only a test, story, fixture or benchmark file uses is not reachable in the production graph. Fallow then gives it review_required, never safe_to_delete, and its evidence has test_only_reference: true, because a removal breaks the test.

The confidence of a verdict depends on the size of the capture. Below 5,000 calls, fallow gives medium confidence at most, and the 240 calls of the demo give medium. Change the two limits with --min-observation-volume and --low-traffic-threshold.

Fallow accepts a V8 coverage directory, one V8 JSON file, or one Istanbul coverage-final.json. When the V8 dump holds source maps, fallow maps the bundle positions back to your source files.

Capture once on your machine

The demo capture is one local capture, and a single local capture is free. Continuous monitoring and more than one capture, for example a V8 directory with more than one JSON file, need a license with the runtime_coverage feature. To try it, start a 30-day trial with fallow license activate --trial --email <addr>. Fallow checks the license offline. fallow license gives the grace period after the expiry date. Runtime data from Fallow Cloud uses a FALLOW_API_KEY, not the local license.

  1. Run the setup. It installs the @fallow-cli/fallow-cov package and writes a recipe for your framework to docs/collect-coverage.md:

    npx fallow coverage setup
  2. Run your app with real traffic and the coverage setting of the recipe, for example NODE_V8_COVERAGE=./coverage node server.js.

  3. Read the capture:

    npx fallow health --runtime-coverage ./coverage

The setup is resumable. Run fallow coverage setup again after the capture, and it continues with the analysis.

Collect continuously with Fallow Cloud

One capture shows one moment. A function that runs once a month does not show in a capture of one hour. Fallow Cloud collects runtime coverage from each deployment over days or weeks, with a small beacon in your app. fallow coverage analyze --cloud then reads the data of the last 1 to 90 days. To set it up, see The Fallow beacon.

Act on a finding

The verdict and its confidence tell you what to do. In the demo, cancelOrder has medium confidence, so check it by hand before you delete it.

VerdictAction
safe_to_delete with high confidenceDelete the function. Ask the owner first when the code is shared.
safe_to_delete with medium confidenceCapture more traffic, or check the function by hand.
review_requiredAsk: is this an error path, a seasonal path or a worker? When it is not, remove the call and the function.
low_trafficFind the users of the feature before you remove it.
coverage_unavailableCheck the source maps and the capture. Do not delete on this verdict.

On a pull request, add --changed-since main or --diff-file <file>. When the change touches a hot path, the report verdict is hot-path-touched, and the reviewer knows that the change runs often.

Fail a run

With --runtime-coverage, a finding with the verdict safe_to_delete, review_required or low_traffic makes fallow health exit with code 1. Add --report-only to show the runtime coverage without a failure. For checks that judge only a change, see Changed code and baselines.

What fallow cannot see

  • A capture holds only the paths that ran during the capture. A short capture misses rare paths, and the report says so with a short capture note.
  • V8 does not track each function. A function that the capture did not track gets coverage_unavailable. A script that the engine did not parse during the capture can be absent.
  • A bundled app needs source maps. Without them, fallow cannot connect a call to a line of your source.
  • A function that ran in tests only is not a production call. Capture from the deployed app, not from a test run.

Reference