tracing-subscriber: fix parsing of filters with multiple span fields #2959
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
Closes #2935
Builds on #2936
Parsing of filters checking for field values is broken when used with more than one field. There may be multiple directives split by commas (e.g.
lib=warn,bin=info
) but the directives themselves can use commas as separators for span fields (e.g.[span-name{field1,field2}]
.Currently, a string containing all directives is first split by commas and then each substring is parsed as its own directive. This does not work when commas are present also because of filters on multiple fields.
Solution
Make the split aware of
{
and}
and do not split on commas that are between those two characters. This fix makes the code work as documented and multiple fields can be matched as long as they do not contain}
in its value (e.g.[name{json_field="{}"}]
).Another potential issue is when a user provides a malformed directive such as
[name{]
then all subsequent directives will be considered as part of the malformed directive so they will not be applied.Alternatives
Since the feature seems to never have worked, we could also decide to use a different separator for fields, e.g.
;
. Then we could simply have[span1{field1=0;field2=2}]=info,[span2{field3;field4}]
and the split between directives would not need to be changed. This would require changes to documentation. Asenv_logger
does not have any feature like this, having a similar format should not be a concern here.