Skip to content

Missing coverage for entire function with #[tracing::instrument(...)] #110486

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
def- opened this issue Apr 18, 2023 · 0 comments
Open

Missing coverage for entire function with #[tracing::instrument(...)] #110486

def- opened this issue Apr 18, 2023 · 0 comments
Labels
A-code-coverage Area: Source-based code coverage (-Cinstrument-coverage) C-bug Category: This is a bug.

Comments

@def-
Copy link

def- commented Apr 18, 2023

I tried this code:

use tracing::warn;

#[tracing::instrument(level = "info", skip_all)]
fn fun() {
    print!("Hello World!");
}

#[cfg(test)]
mod tests {
    use crate::fun;

    fn function() {
        fun();
    }
}

And created a coverage report of it with:

RUSTFLAGS="-C instrument-coverage" cargo test
rust-profdata merge -sparse -o 1.profdata **/*.profraw
rust-cov show target/debug/deps/coverage_mini-280555d4395f82aa --instr-profile 1.profdata main.rs

I expected to see the function fun marked as covered.

Instead, it is shown as not being possible to cover:

    1|      1|use tracing::warn;
    2|       |
    3|      2|#[tracing::instrument(level = "info", skip_all)]
    4|       |fn fun() {
    5|       |    print!("Hello World!");
    6|       |}
    7|       |
    8|       |#[cfg(test)]
    9|       |mod tests {
   10|       |    use crate::fun;
   11|       |
   12|      1|    #[test]
   13|      1|    fn function() {
   14|      1|        fun();
   15|      1|    }
   16|       |}

Without the #[tracing::instrument(...)] it works fine:

    1|      1|use tracing::warn;
    2|       |
    3|      1|fn fun() {
    4|      1|    print!("Hello World!");
    5|      1|}
    6|       |
    7|       |#[cfg(test)]
    8|       |mod tests {
    9|       |    use crate::fun;
   10|       |
   11|      1|    #[test]
   12|      1|    fn function() {
   13|      1|        fun();
   14|      1|    }
   15|       |}

Meta

rustc --version --verbose:

rustc 1.71.0-nightly (7908a1d65 2023-04-17)
binary: rustc
commit-hash: 7908a1d65496b88626e4b7c193c81d777005d6f3
commit-date: 2023-04-17
host: x86_64-unknown-linux-gnu
release: 1.71.0-nightly
LLVM version: 16.0.2
@def- def- added the C-bug Category: This is a bug. label Apr 18, 2023
@wesleywiser wesleywiser added the A-code-coverage Area: Source-based code coverage (-Cinstrument-coverage) label Apr 18, 2023
AMDmi3 added a commit to repology/repology-rs that referenced this issue Nov 15, 2024
Lines for functions with tracing::instrument are missing from coverage, so
it's calculated incorrenctly, see [1].  As a temporaty fix, we introduce
`coverage` feature, which basically disables tracing::instrument
attrubutes.

[1] rust-lang/rust#110486
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-code-coverage Area: Source-based code coverage (-Cinstrument-coverage) C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

2 participants