Skip to content

tracing span not closed after response received #2830

@YuKi74

Description

@YuKi74
#[tokio::main]
async fn main() -> anyhow::Result<()> {
    tracing_subscriber::fmt()
        .with_env_filter(EnvFilter::from_str(&format!(
            "off,{}=trace",
            env!("CARGO_BIN_NAME").replace("-", "_")
        ))?)
        .with_span_events(FmtSpan::NEW | FmtSpan::CLOSE)
        .init();
    let client = reqwest::Client::new();
    client.get("https://google.com").send().instrument(debug_span!("request")).await?;
    // drop(client);
    tokio::time::sleep(Duration::from_secs(3)).await;
    Ok(())
}

When running the code above, the span close event is not printed until the program terminates, with the time.idle exceeding 3 seconds. If the comment for drop(client) is removed, the span close event will be printed immediately after the request is completed, with the time.idle less than 1 second.

Is this a bug with reqwest or tracing?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions