Closed rustonaut closed 1 week ago
Some additional comments:
I hadn't been aware that the compatibility problems might be bigger then expected until after nearly finishing writing this PR, I still want to present it but I'm no longer sure if it's the best way to fix the problem. But at least we should update the documentation + add some (? but how ?) way to handle cases like %true
/ ?10
etc. and test for this cases, too.
maybe a [{field=true}]
should match all of true
, %true
and ?true
?
The reason the integration tests are a bit more complicated is because there is the issue that [{field}]
filters apply to events but [{field=value}]
filters only apply to spans but not events.
Closed as fixing the issues also introduce breaking changes, instead following will be done:
allow programmatically creating filters #3018 (is a workaround for the issue this PR was for and a long requested feature)
TODO PR to add integration tests (based on the ones from this PR) to test that other PRs don't accidentally break parsing/filtering related to wrapping "
quotes
TODO PR to update documentation to be more clear about limitations
Motivation
The documentation states that
[span_b{name=\"bob\"}]
should match spans where the value ofname
isbob
but it does match spans where the value ofname
is"bob"
.Additionally there is no good way to match strings which happen to be true, false or a number.
[{value="true"}]
matches the rust stringr#""true""#
and[{value=true}]
only matches a bool value true but not a stringtrue
.Solution
"
quotes we stip them when parsingValueMatach
/MatchDebug
"bob
,bob"
or"
we treat it as a syntax error)bo"b
) is not changed (i.e.bo"b
matchesbo"b
)Partially Fixes: #1181 Fixes: #2809
Stability Considerations
some malformed/ambiguous directives did pass parsing, it might make sense to change the behavior for unbalanced outer quotes (
"bob
,bob"
) to not create an error but parse include the"
in the regex like previouslyif anyone did accidentally log a string as debug (e.g.
foo = %"my string"
) then the previous filter happened to work, and this happening isn't even that unlikely (due toinstrument
) . At the same time not stripping the quotes is a huge problem for anything of which the debug/display output istrue
/false
or a numberDirective
parsing algorithm and some form to opt into it. We could start by defining a grammar for the syntax. Avoiding ambiguity and allowing escaping of various characters (e.g.,[{}]
) on the level of the directive string representation. Which would fix multiple issues caused from the current formats ambiguities.EnvFilter::builder2()
and similarEnvFilter
after providing a alternative more robust implementation could also work (e.g. aFilterDirectives
given that theEnvFilter
is IMHO by now more focused on flexible filter directives then on).Directives
in which case external crates can provide their own parsing solutions (or e.g. from config deserialization) without having to re-implement the filter application logic. I really like this idea. Through that would make theEnvFilter
have even less to do with the env.