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

Filter to detect/exclude events sourced from the log crate via tracing-log #3059

Open
lcmgh opened this issue Aug 14, 2024 · 1 comment
Open

Comments

@lcmgh
Copy link

lcmgh commented Aug 14, 2024

Feature Request

Crates

Motivation

When using tracing with tracing-log to convert log crate entries to tracing events I'd like to exclude such events from being exported to my tracing backend. For filtering one can for instance utilize Metadata but I can't find any option to tell whether an event was sourced from a log entry. So I currently must export all my logs to the tracing backend which is what I want to prevent.

Proposal

  • Somehow mark tracing events sourced from log so it can be filtered later on

Alternatives

I found tracing quite useful as primary logger due to it's layer system. Maybe I am using the wrong tools here and should rather take a regular logger and then convert tracing events to logs?

@kaffarell
Copy link
Contributor

Hmm this is kind of a hacky solution, but:

    tracing_subscriber::registry()
        .with(tracing_subscriber::fmt::layer())
        .with(filter_fn(|meta| {
            meta.fields().field("log.target").is_none()
        }))
        .init();

    log::debug!("this is a log line");
    tracing::debug!("this is a tracing line");

log-events do have some metadata that distinguish them: log.target, log.module_path, log.file, log.line. But this is not really a fool-proof solution. Maybe we could add a specific field like: source: log or something?

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

2 participants