Skip to content

Commit

Permalink
change OR to AND logic for filtering logs (open-telemetry#12198)
Browse files Browse the repository at this point in the history
change OR to AND logic for filtering logs - as desribed, and as is done for span filtering
  • Loading branch information
zeitlinger committed Jul 11, 2022
1 parent 32d8141 commit 2452d43
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
8 changes: 4 additions & 4 deletions internal/coreinternal/processor/filterlog/filterlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ func NewMatcher(mp *filterconfig.MatchProperties) (Matcher, error) {
// supported to have more than one of these specified, and all specified must
// evaluate to true for a match to occur.
func (mp *propertiesMatcher) MatchLogRecord(lr plog.LogRecord, resource pcommon.Resource, library pcommon.InstrumentationScope) bool {
if lr.Body().Type() == pcommon.ValueTypeString && mp.bodyFilters != nil && mp.bodyFilters.Matches(lr.Body().StringVal()) {
return true
if lr.Body().Type() == pcommon.ValueTypeString && mp.bodyFilters != nil && !mp.bodyFilters.Matches(lr.Body().StringVal()) {
return false
}
if mp.severityTextFilters != nil && mp.severityTextFilters.Matches(lr.SeverityText()) {
return true
if mp.severityTextFilters != nil && !mp.severityTextFilters.Matches(lr.SeverityText()) {
return false
}

return mp.PropertiesMatcher.Match(lr.Attributes(), resource, library)
Expand Down
7 changes: 7 additions & 0 deletions internal/coreinternal/processor/filterlog/filterlog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,13 @@ func TestLogRecord_Matching_False(t *testing.T) {
},
},
},
{
name: "log_severity_text_regexp_dont_match",
properties: &filterconfig.MatchProperties{
Config: *createConfig(filterset.Regexp),
LogSeverityTexts: []string{"debug.*"},
},
},
}

lr := plog.NewLogRecord()
Expand Down
7 changes: 7 additions & 0 deletions unreleased/fix-log-filter.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
change_type: bug_fix

component: filterlog

note: change OR to AND logic for filtering logs - as desribed, and as is done for span filtering

issues: [11439]

0 comments on commit 2452d43

Please sign in to comment.