Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

tracing-subscriber 0.3.1 does not respect RUST_LOG #1697

Closed
theduke opened this issue Nov 3, 2021 · 9 comments
Closed

tracing-subscriber 0.3.1 does not respect RUST_LOG #1697

theduke opened this issue Nov 3, 2021 · 9 comments

Comments

@theduke
Copy link

theduke commented Nov 3, 2021

Bug Report

Version

tracing-subscriber 0.3.1

Platform

Linux

Description

tracing-subscriber seems to incorrectly handle the RUST_LOG env var.

After tracing_subscriber::fmt::init() I only get INFO and above events, regardless of the RUST_LOG env var (RUST_LOG=trace, RUST_LOG=crate=trace, ...)

Downgrading to 0.2 fixes this.

(I checked the release notes for changed behaviour, but it seems like there aren't any relevant alterations)

@davidbarsky
Copy link
Member

davidbarsky commented Nov 3, 2021

I’ll update the changelog later, but the EnvFilter functionality is now behind an off-by-default feature flag called env-filter. You’ll need to add that to your Cargo.toml.

(The documentation for EnvFilter alludes to this, but this should be in a more prominent spot: https://docs.rs/tracing-subscriber/0.3.1/tracing_subscriber/struct.EnvFilter.html)

@hawkw
Copy link
Member

hawkw commented Nov 3, 2021

I’ll update the changelog later, but the EnvFilter functionality is now behind an off-by-default feature flag called env-filter. You’ll need to add that to your Cargo.toml

The changelog does mention the feature flagging change: https://github.com/tokio-rs/tracing/blob/v0.1.x/tracing-subscriber/CHANGELOG.md#breaking-changes but it may not be obvious what behavior this changes, so we might want to clarify that changelog entry.

I think the most important docs improvement, though, might be to change the documentation for methods like fmt::init, that include an EnvFilter in the configured subscriber, to explicitly state that the feature flag is necessary for RUST_LOG filtering.

@hawkw
Copy link
Member

hawkw commented Nov 3, 2021

I think the most important docs improvement, though, might be to change the documentation for methods like fmt::init, that include an EnvFilter in the configured subscriber, to explicitly state that the feature flag is necessary for RUST_LOG filtering.

Actually, now that I think about it, we could probably change init, at least, to include a Targets filter instead of EnvFilter when the feature flag is disabled. That way, we would still get RUST_LOG filtering, but would specifically not enable span field value filtering (which is why EnvFilter is feature flagged).

hawkw pushed a commit that referenced this issue Nov 3, 2021
…#1700)

Resolves #1697 by documenting this change in the CHANGELOG.md.
@rcoh
Copy link

rcoh commented Nov 9, 2021

perhaps we could log a warning if RUST_LOG is set but the feature isn't enabled in tracing_subscriber::fmt::init()? I suspect this will save a lot of people a lot of debugging time.

@dzamlo
Copy link

dzamlo commented Nov 15, 2021

Despite enabling the env-filter, using tracing_subscriber::fmt::init() is not enough.

I have to manually add the filter:

tracing_subscriber::fmt()
        .with_env_filter(EnvFilter::from_default_env())
        .with_writer(non_blocking)
        .init();

Is it corect that this is not the expected behaviour?

ishitatsuyuki added a commit to ishitatsuyuki/tracing that referenced this issue Dec 16, 2021
ishitatsuyuki added a commit to ishitatsuyuki/tracing that referenced this issue Dec 16, 2021
ishitatsuyuki added a commit to ishitatsuyuki/tracing that referenced this issue Dec 29, 2021
hawkw added a commit that referenced this issue Dec 29, 2021
…t enabled(#1781)

The removal of `env-filter` from the default features in 0.3.0 has
caused a lot of developer frustration. This PR changes
`tracing_subscriber::fmt::init()` and `try_init` to fall back to adding
a `Targets` filter parsed from the `RUST_LOG` environment variable,
rather than a `LevelFilter` with the default max level.

This way, `RUST_LOG`-based filtering will still "just work" out of the
box with the default initialization functions, regardless of whether or
not `EnvFilter` is enabled.

Closes #1697

Co-authored-by: Eliza Weisman <eliza@buoyant.io>
@Firstyear
Copy link

I can reproduce this as well:

[package]
name = "tracing_demo"
version = "0.1.0"
edition = "2021"

[dependencies]
tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter", "std", "fmt"] }
#[macro_use]
extern crate tracing;

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

    debug!("This is a debug message");

    trace!("This is a trace message");
}

Using RUST_LOG=trace or debug both will not show the above messages.

tracing-subscriber v0.3.5
tracing v0.1.29
rustc 1.57.0 (f1edd0429 2021-11-29)

@kafji
Copy link

kafji commented Jan 1, 2022

@Firstyear that's because tracing_subscriber::fmt().init() is not same as tracing_subscriber::fmt::init().

  • tracing_subscriber::fmt::init() => initialize subscriber with opinionated configurations i.e. with with_env_filter(EnvFilter::from_default_env())
  • tracing_subscriber::fmt().init() => create subscriber builder (with empty configurations) and then initialize it as global subscriber

It is confusing, #1329

tl;dr

  • add with_env_filter(EnvFilter::from_default_env())
  • or use fmt::init()

@Firstyear
Copy link

Yes, I think the docs also suggested at one point .init() as well, as I remember copy-pasting this line.

@davidbarsky
Copy link
Member

Gonna close this since this was fixed in tracing-subscriber 0.3.5 with #1781.

kaffarell pushed a commit to kaffarell/tracing that referenced this issue May 22, 2024
kaffarell pushed a commit to kaffarell/tracing that referenced this issue May 22, 2024
…t enabled(tokio-rs#1781)

The removal of `env-filter` from the default features in 0.3.0 has
caused a lot of developer frustration. This PR changes
`tracing_subscriber::fmt::init()` and `try_init` to fall back to adding
a `Targets` filter parsed from the `RUST_LOG` environment variable,
rather than a `LevelFilter` with the default max level.

This way, `RUST_LOG`-based filtering will still "just work" out of the
box with the default initialization functions, regardless of whether or
not `EnvFilter` is enabled.

Closes tokio-rs#1697

Co-authored-by: Eliza Weisman <eliza@buoyant.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants