tracing icon indicating copy to clipboard operation
tracing copied to clipboard

Allow empty value match for fields

Open MattesWhite opened this issue 8 months ago • 0 comments

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.

MattesWhite avatar Jun 23 '24 10:06 MattesWhite