tokio-rs / tracing

Application level tracing for Rust.
https://tracing.rs
MIT License
5.39k stars 707 forks source link

Allow empty value match for fields #3015

Open MattesWhite opened 3 months ago

MattesWhite commented 3 months ago

Motivation

In the current version of EnvFilter, the directive [span{field=}] does not work as expected.

The directive [span{field}] filter for all spans span that have a field field while the directive [{field=a}] filters for all spans span where the field field has the value a. In contrast, the directive [span{field=}] filters only for spans span. IMHO this is unexpected behavior.

Solution

Digging into the code for parsing Directives the regex for field matches didn't consider the field= case. This PR changes the regex so that field= is interpreted as a match on an empty string.

With regex enabled this means that now field= behaves like field.

Alternative solution

Instead of accepting the field= directive, it could trigger an error instead invalidating the whole directive.