Skip to content

Coverage information is wrong when using tracing #131119

Open
@xd009642

Description

@xd009642

So found an interesting thing when developing cargo-tarpaulin and confirmed it exists also with cargo-llvm-cov and using the raw llvm tools. When #[tracing::instrument] is added to a function the function body is not included in the coverage instrumentation. This doesn't happen with #[tokio::main] and I'm yet to create a more minimal reproduction with a less intense proc macro.

Project setup:

cargo new --lib tracing-instrument
cargo add tracing

In src/lib.rs

use tracing::instrument;

#[instrument]
fn instrumented_function() {
    println!("Hello");
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn is_it_hit() {
        instrumented_function();
    }
}

If you run something like cargo llvm-cov --html on this project you'll see only #[instrument] is marked as covered. If we comment out #[instrument] then the function signature, body and closing brace are marked as covered regions of codes.

This suggests to me there's something a bit wrong with the llvm instrumentation setup and how it interacts with procedural macros.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-code-coverageArea: Source-based code coverage (-Cinstrument-coverage)A-proc-macrosArea: Procedural macrosC-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions