Skip to content

#[instrument(ret)] behaviour does not match documentation, also reports errors #2963

@Xiretza

Description

@Xiretza

Bug Report

Version

tracing-attributes v0.1.27 (proc-macro)
tracing-core v0.1.32
tracing-log v0.2.0
tracing-subscriber v0.3.18
tracing v0.1.40

Platform

Arch Linux, kernel 6.8.5-arch1-1

Crates

tracing-attributes

Description

The documentation claims that:

Note: if the function returns a Result<T, E>, ret will record returned values if and only if the function returns Result::Ok.

This is however only the case when the #[instrument] macro is also given the err parameter; otherwise, the return value is printed unconditionally (whether it is Ok or Err). This can also be seen in the implementation, which has a match block when err is specified, but does not have a match block when only ret is specified.

I've been trying to do some code archaeology to find out why it was implemented and documented this way in #1716, but I've come up empty.

Reproducer:

use tracing::instrument;

fn main() {
    tracing_subscriber::fmt().init();

    let _ = make_error();
}

#[instrument(ret)]
fn make_error() -> Result<(), &'static str> {
    Err("error!")
}
$ cargo run --quiet
2024-05-05T21:59:22.720067Z  INFO make_error: repro: return=Err("error!")

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions