How CoverOps measures

This page explains the model behind every CoverOps screen: what an agent records, where it lands, and how the pieces add up to the numbers on Coverage monitoring, Run detail, Impact, Test selection and the Quality gate. Read it once before you set up agents for a real system.

Projects and agent tokens

A project is one product's workspace. It scopes everything: agents, runs and the tests in them, KPIs.

An agent token (cov_…) is created on Agents, belongs to one project and is shown once. It is registered for an environment: the form offers ci, local, staging and prod. Whatever an agent sends with that token lands in the token's project. Reports never name a project themselves, so a leaked token cannot write into another project.

What an agent records

An agent runs inside your service process, for example through -javaagent on the JVM. It records three kinds of data.

  • Line coverage. Which lines (and functions and branches) of your own code ran. The agent counts from its own start, or from the moment it was last told to reset, and uploads that running total every flush cycle (30 seconds by default for the Java agent). Source text is not part of it. Source is uploaded separately, and the dashboard shows bare line numbers until it arrives.
  • Per-test lines. Which lines each test touched. This is what links a test to the code it exercises, and it is what Impact and Test selection read.
  • Traces. With tracing on, the agent records each request's call chain: which methods ran, in what order, at what depth. A chain continues across services through the X-CoverageOps-Trace header, so one click in a browser becomes one chain through every service it touched. Each service the request crosses is a hop. Agents can sample traces: the Java agent's traceSampleEvery records one request in every N (1, every request, by default). A request that was not sampled still appears as a hop, marked sampled: false, without its methods. With the Java agent, sampling thins out traces only; line coverage still counts every request.

Runs and run keys

A run is one measurement, identified inside the project by its run key. Every service and runner that sends the same key takes part in the same run.

Where the key comes from, in order (the same in every agent, the test-runner plugins and the CLI):

  1. COVERAGEOPS_RUN_KEY, if you set it.
  2. The CI system's build id: the first of GITHUB_RUN_ID, BUILD_NUMBER, CI_PIPELINE_ID, BUILD_BUILDID and CIRCLE_WORKFLOW_ID that is set, trimmed and sent as CI wrote it, with no prefix.
  3. Otherwise local-YYYYMMDD, one key per day. The CLI has no such fallback: outside CI it sends no run key unless you give one.

So the services of one build and its test results land in the same run without extra configuration. A value that is only spaces counts as not set. While a monitoring window is open, agents report into it instead (see below), COVERAGEOPS_RUN_KEY or not; when it is stopped they go back to the key above.

A local-YYYYMMDD key is treated specially: while coverage monitoring is on, the server files such traffic into the monitoring window instead of a per-day run. Explicit keys, such as CI ids or anything a person set, are never redirected this way.

A run also has a branch and a commit: the Flaky tests page splits a test's results per branch and compares runs of one commit, test selection reads footprints measured on the change's merge base, and the run list shows both. They come from whoever reports into the run:

  • Services' agents send COVERAGEOPS_BRANCH and COVERAGEOPS_COMMIT_SHA when they are set (the Java agent also reads GIT_BRANCH and GIT_COMMIT).
  • Test-runner plugins detect them when they open the run: COVERAGEOPS_BRANCH and COVERAGEOPS_COMMIT_SHA first, then the CI system's own variables (GitHub Actions, GitLab CI, Jenkins, Azure Pipelines, CircleCI, Bitbucket Pipelines, Buildkite, TeamCity), then git in the suite's directory. On a pull or merge request they report its source branch and its own head commit, never the merge ref or GitHub's merge commit. Without git they open the run without them. So a project whose only reporter is a test runner has branches and commits too.

The first report that states them wins; a later one never replaces them. A report from another checkout (a different commit or branch than the run already has, such as a service built from main while the suite runs on a pull request's branch) changes neither, so a run's branch and commit always belong together. A value that is not a commit id (7 to 64 hex characters) or not a branch (HEAD, refs/pull/12/merge) is ignored.

A test runner opens its run before the first test (the Playwright, Cypress and Selenium/JUnit integrations do this themselves). A run is finished by its runners, or by hand with Finish for always-on runs. A finished run's verdict follows its tests: any failure means failed, otherwise any pass means passed, and no verdicts at all means aborted.

How runners finish a run:

  • Each runner plugin (Jest, Vitest, Playwright, Cypress, WebdriverIO, pytest, Robot Framework, JUnit 5, TestNG) joins the run as one session when it starts and says it is done when its tests end and their verdicts are stored. The run closes when every session that joined has finished. With a runner's own sharding (--shard=2/3 in Playwright, Jest, Vitest and WebdriverIO, pytest-split's groups) a session knows how many shards there are, and the run also waits for shards that have not started yet. pytest-xdist workers are one session: the controller's.
  • After the last session the run stays open for a short grace (60 seconds by default), for a shard that starts a moment later and for the services' last coverage. A session that joins during the grace calls the close off. The run's duration ends at the last session's finish.
  • A monitoring window is never closed by a runner, nor is the shared local-YYYYMMDD run. Services' agents never finish a run.
  • A session that crashes, is interrupted, or whose verdicts were not stored never says it is done, so the run stays running until someone uses Finish, the pipeline finishes it, or it has received no data for 6 hours.
  • Idle runs close themselves. A run that has received no data of any kind for 6 hours (COVEROPS_RUN_IDLE_CLOSE_HOURS; 0 turns it off) is closed by the server with the same verdict rule, as if it ended at its last data, and its page says "Closed after 6 h without data". Data means a runner session starting or finishing, verdicts, coverage or a trace; an agent's poll does not count, and agents send no coverage while nothing changed, so a service that is up but unused does not keep a run open. Monitoring windows are never closed this way, and the shared local-YYYYMMDD run only once its day is over. A run with a fixed key that is meant to stay open for days (COVERAGEOPS_RUN_KEY=staging) and goes quiet is closed too: use a monitoring window for always-on measurement.
  • Finishing again changes nothing, and a failed run never becomes passed. A closed run is never reopened: data that arrives later is stored in it, and failures that arrive after the close (a re-run of one job, a slow job after an idle close) make it failed.
  • When the runners cannot know the whole pipeline (a matrix job that may start after the others have ended, several tools sharing one run key), either tell them how many sessions there are with COVERAGEOPS_RUN_PARTS, or set COVERAGEOPS_FINISH_RUN=false and close the run once at the end with coverageops run finish (the GitHub Action's finish command). Finishing is off for a runner whenever COVERAGEOPS_FINISH_RUN is false, 0, no or off.

Each test is passed, failed, skipped or has no result. The last is a test an agent reported with coverage only (it knows which lines the test ran, not whether it passed) and no runner has given a verdict for, because the verdict has not arrived yet or never will (the runner crashed, or no runner plugin reports). It is neither a pass nor a failure: counts show it apart, the pass rate, fail rates and flaky scoring leave it out, a gate that requires passing tests fails on it, and it is not a verdict when a run is finished. A verdict that arrives later replaces it; coverage never replaces a verdict. Tests recorded before this state existed keep the passed they were stored with.

Monitoring windows

Coverage monitoring is a run that every agent of the project reports into, for as long as it is open. Use it for long measurements: days of manual testing and automated passes adding up to one number.

  • Start coverage monitoring (with an optional label) opens a window. The first window open is the primary one. Agents poll the server every flush cycle. When they see a new window, they send what they still owed the previous run, reset their counters and join it, so the window starts at 0% with the full denominator.
  • Starting a second window while one is open does not disturb the first. The agents keep reporting into the primary window. The later window receives the same stream minus a baseline: what each participant had already counted when the window opened. It therefore starts at zero, both windows grow together, and either can be stopped without touching the other. The run list marks such a window "measured from when it opened". It opens with every participant of the primary window listed, so idle services show as watched too.
  • Stop closes a window with the verdicts it holds. If it was the primary window, the oldest window still open takes over and drops its baseline, because the agents reset when the key changes. If none is left, monitoring is off, and on its next poll every agent goes back to its own run key the same way it moves to a new window: it sends what it still owed the window, resets its counters and rejoins its own run. A poll that fails moves nothing; an agent stays where the last answer put it.
  • Resume monitoring reopens the window that was last stopped. Coverage keeps merging into the totals it already had.
  • A monitoring window with no coverage uploads of its own is derived from its traces. The lines its traced requests ran are measured against the primary window's lines. Branches read zero in that case, because traces carry no branch data.
  • If a service is redeployed with a changed file during a window, that file's earlier coverage is dropped and counting starts again from the new build. Adding the two would put coverage on lines that have moved.

Participants

A participant is one agent token, under one service name (the agent's shard, by default the service name), from one replica, inside one run.

  • Within a run a participant's coverage only grows. Each upload is that process's running total since its own start, so two uploads of the same participant are merged by taking the larger count per line, not by adding them. A process that restarts mid-run keeps what it had covered before.
  • A service's coverage is its replicas merged: a line any replica ran is covered.
  • A run's coverage is all of its services merged, each file counted once.

Replicas

Every agent sends the replica it runs as on every report, in the X-CoverageOps-Instance header (or the instance query on its poll). Set it with COVERAGEOPS_INSTANCE; by default it is the host name, which in Kubernetes is the pod name.

  • Five pods of user-service are five instances: five rows under that service on Agents, five participants in the run, and five against the package's instance limit.
  • Each pod is its own participant because it counts from its own start. The run shows the service once, with the pods merged.
  • The instance limit counts replicas that reported in the last 15 minutes, so pods a rollout replaced stop counting soon after they are gone. See Licence and usage.
  • An agent too old to send an instance puts all its replicas into one shared participant.

Environments

COVERAGEOPS_ENVIRONMENT (test, preprod, prod…) names the environment on every report, as the X-CoverageOps-Environment header. When it is not set, the token's environment applies. Names are compared in lower case, so PreProd and preprod are one environment.

  • One run or monitoring window can hold pods of several environments. Each participant keeps its own environment, so nothing mixes. When a run holds more than one environment, Run detail offers an Environment filter, and the run list shows each run's environments.
  • One token can therefore serve every environment.
  • Declaring a production environment needs a package that includes production, the same as registering a production token. Names starting with prod, production, prd or live count as production.

Test context

A test tool tells CoverOps three things on the traffic it sends: the test name (suite::name), an optional test id (the id your test management tool uses), and an optional run. Each field is taken from the first channel that has it:

#Channeltesttest idrun
1HTTP headersX-CoverageOps-TestX-CoverageOps-Test-IdX-CoverageOps-Run
2W3C baggagecoverops.testcoverops.test_idcoverops.run
3Cookie covctxtestidrun
4Query stringcovtestcovtestidcovrun

Values are percent-encoded. The cookie is the way for Selenium, because a browser cannot add custom headers but sends cookies by itself. The test name may be up to 600 characters, the test id and run up to 200.

Traffic can only choose among runs that are already open. Anyone who can reach a service can send these headers, so a run named by traffic is honoured only when it exists in the token's project and is running, or finished less than 10 minutes ago (for late flushes). Otherwise the work lands in the agent's own run, and the trace response says "test_run": "unknown". Traffic never opens a run; the test tool opens it with its token.

Between services the context travels as the three X-CoverageOps-* headers. Whether a service passes them on by itself depends on its agent:

AgentOutbound HTTPMessages (Kafka, RabbitMQ)
JavaAutomatic: the JDK's HttpURLConnection and HttpClient, Apache HttpClient 4 and 5, OkHttp (so RestTemplate and Feign too)Automatic: Kafka producer and consumer, Spring Kafka listeners, RabbitMQ publish, Spring AMQP listeners
NodeAutomatic: http, https, fetchBy hand
GoOne line: coverageops.Transport(nil) on the http.ClientBy hand
Python, .NET, PHPBy hand, with the agent's outbound-headers helperBy hand

On the Java side, Spring WebClient, gRPC, a raw RabbitMQ basicConsume consumer, Kafka batch listeners and work handed to another thread are not followed automatically; the Java agent's documentation shows how to carry the context there. A hop that does not carry the headers still has its coverage in the run, but not under the test, and the chain breaks there. The Java agent's propagation=off turns its automatic forwarding off.

Parallel tests

Per-test line coverage comes from counters that a whole service process shares. When two tests' traffic reaches the same process at the same time, their lines cannot be told apart. CoverOps takes the safe side:

  • While tests overlap, every test that had traffic in that span gets all of its lines. No test loses a line; a changed line may select more tests, never fewer.
  • The overlap is recorded per test. The run page says that the test ran at the same time as N other tests against the same service, so its lines may include theirs.
  • Requests, endpoints, services and methods come from per-request traces, which never mix, so those stay exact.

The .NET agent records lines per request, and PHP serves each request in its own process, so neither shares windows. Java, Node, Python and Go do.

Shared services

A backend several products call, such as core banking under internet and mobile banking, belongs to one project and keeps one token. The account owner shares it in two steps:

  1. On Agents, tick Organisation-wide on the token. The account's other projects may now include the services reporting with it.
  2. On Projects, open the consuming project and choose the services it includes under Shared services.

From then on:

  • A test of the consuming project whose traffic reaches the shared service carries its run in the X-CoverageOps-* headers. When that run is open in the consuming project, the code the shared service ran for the request is filed there, under that test. Only projects of the same account are looked at.
  • While the consuming project is monitoring, all of the shared service's coverage in that time also joins the consuming project's monitoring windows, not only the part its own traffic caused.
  • The instance and its source count once, in the project that owns the token.
  • Data never crosses into another account.
  • Turning Organisation-wide off removes the service from every project that included it.

How it feeds Impact, Test selection and the Quality gate

  • Impact takes the lines a change touched (from git) and the lines each test executed the last time it ran, and lists the tests whose footprint overlaps the change, ranked by how many changed lines they ran.
  • Test selection skips a test only when there is evidence it cannot see the change: CoverOps has the test's footprint, the footprint misses every changed line, and every changed file is code the agents measure. Without that evidence the test runs, and when the change itself cannot be read in full, everything runs. Shared windows from parallel tests make it select more, never fewer.
  • The Quality gate asks, for a build's run (the latest unless a run key is given): of the lines this change touched, how many did the tests execute? Changed lines the agents never measured, such as comments, configuration or a service that did not run, count neither for nor against.

Glossary

EnglishTurkishMeaning
ProjectProjeOne product's workspace; everything is scoped to it.
AgentAjanThe library inside your service that records coverage and traces.
Agent tokenAjan token'ıThe credential an agent reports with; decides the project and the default environment.
CoverageKapsamWhich lines, functions and branches ran.
RunKoşumOne measurement, identified by its run key.
Run keyKoşum anahtarıThe name every participant of a run sends.
Monitoring windowİzleme penceresiA run every agent of the project reports into while it is open.
BaselineBaşlangıç noktasıWhat each participant had counted when a later window opened; that window's zero.
ParticipantKatılımcıOne token, service and replica inside one run.
Replica / podKopya / podOne process of a service, told apart by COVERAGEOPS_INSTANCE.
InstanceInstanceA replica as the package counts it: one that reported in the last 15 minutes.
EnvironmentOrtamWhere a process runs: test, preprod, prod…
FootprintAyak iziWhat one test did on the backend: requests, services, methods, lines.
Traceİstek iziOne request's call chain across services.
HopAdımOne service a traced request crossed.
SamplingÖrneklemeRecording the call chain of only one request in N.
Shared servicesPaylaşılan servislerServices of an organisation-wide token that another project includes.
Organisation-wideOrganizasyon geneliA token whose services the account's other projects may include.
PackagePaketThe set of limits an account or installation is held to.
Add-onEk paketExtra units on top of a package's limit.
LimitSınırThe most of one thing a package allows.