Line coverage showing incorrect values when `tracing::instrument` attribute is used
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:

Coverage with tracing::instrument commented out:

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
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from mozilla/grcov
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
-
Difficulty 4/5 3-5 days Newbie friendliness 48/100
-
`grcov` can panic on several malformed coverage inputs instead of reporting parse/output errors Open
Difficulty 4/5 3-5 days Newbie friendliness 52/100
-
Difficulty 3/5 1-2 days Newbie friendliness 68/100
-
Difficulty 3/5 1-2 days Newbie friendliness 45/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
kwakseongjae/auto-hwp#319 ·
-
area:cli bug filter-quality good first issue priority:medium
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
-
Difficulty 1/5 Under an hour Newbie friendliness 72/100
bevyengine/bevy#25861 ·
-
comp-datalake
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
ClickHouse/ClickHouse#121222 ·
-
enhancement remote
Difficulty 2/5 1-3 hours Newbie friendliness 68/100