Line coverage showing incorrect values when `tracing::instrument` attribute is used

Open
#950 0 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
rust
Domain
testing-qa

Research direction

Reproduce the report using the Docker, cargo, llvm-tools-preview, and grcov commands provided, comparing HTML coverage with tracing::instrument enabled and disabled. No source file or test is named; completion means explaining or correcting the discrepancy so the untested line is excluded and the reported coverage matches the expected 94.74%.

Written by the indexing model from the issue text.

Description

I'm using tracing::instrument attribute to collect telemetry data in some of my functions. However, this is generating inconsistent line coverage values. For instance, see the following two screenshots (the first one with tracing::instrument enabled and the second with it disabled).

Coverage with tracing::instrument uncommented:
image

Coverage with tracing::instrument commented out:
image

94.74% of line coverage should be the correct value since line 8 is not being tested. However, this line coverage is not detected when the tracing::instrument attribute is enabled, ultimately presenting an incorrect 100% line coverage value.

So is this indeed an issue? And is there something I can do to solve this? I'd like to continue using tracing::instrument, but get the correct coverage results.

Here it's the commands I'm using to generate the grcov results:

IMAGE=rust:1.65.0; docker run -v "$PWD":/proofs -w /proofs --privileged -it "$IMAGE"

export RUSTFLAGS="-Cinstrument-coverage"
export LLVM_PROFILE_FILE="proofs-%p-%m.profraw"
cargo install grcov@0.8.13
rustup component add llvm-tools-preview
cargo build
cargo test
grcov . --binary-path ./target/debug/ -s . -t html --branch --ignore-not-existing -o ./code_coverage/

My Cargo.toml:

[package]
name = "test-coverage"
version = "0.1.0"
edition = "2021"

[dependencies]
tracing = { version = "0.1.36", features = ["attributes"] }
Dominant language
Rust
Stars
1.4k
Forks
170
Avg merge
3d 10h
Merged PRs (30d)
4

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from mozilla/grcov

All issues in mozilla/grcov

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.