Skip to content

Nested event generation bypasses level filteringΒ #2448

@nilfit

Description

@nilfit

Bug Report

Version

tracing v0.1.37
tracing-attributes v0.1.23
tracing-core v0.1.30
tracing-subscriber v0.3.16
tracing-log v0.1.3

Description

When a formatting argument of a tracing event macro (e.g. debug!) itself produces a tracing event, level filtering for the outer event is ignored. The level of the inner event does not seem to make a difference.

use tracing_subscriber::{filter::LevelFilter, prelude::*, Layer};

fn main() {
    let everything_layer = tracing_subscriber::fmt::layer().with_writer(std::io::sink);
    let stdout_layer = tracing_subscriber::fmt::layer()
        .without_time()
        .with_filter(LevelFilter::ERROR);
    tracing_subscriber::registry()
        .with(stdout_layer)
        .with(everything_layer)
        .init();

    tracing::error!("just an error");
    tracing::debug!("just debug");
    tracing::debug!("instrumented {:?}", instrumented());
    tracing::debug!("tracing in callee {:?}", nested());
    tracing::debug!("directly nested {:?}", tracing::trace!(""));
}

#[tracing::instrument()]
fn instrumented() {}

fn nested() {
    tracing::warn!("nested");
}

Actual stdout:

ERROR tracing_bug: just an error
DEBUG tracing_bug: instrumented ()
DEBUG tracing_bug: tracing in callee ()
DEBUG tracing_bug: directly nested ()

Expected stdout:

ERROR tracing_bug: just an 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