Skip to content

Commit

Permalink
code review
Browse files Browse the repository at this point in the history
  • Loading branch information
atoulme committed Apr 1, 2022
1 parent f6c86a4 commit 1a298d0
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
2 changes: 1 addition & 1 deletion internal/coreinternal/processor/filterlog/filterlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ 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 pdata.LogRecord, resource pdata.Resource, library pdata.InstrumentationScope) bool {
if lr.Body().Type() == pdata.ValueTypeString && mp.bodyFilters.Matches(lr.Body().StringVal()) {
if lr.Body().Type() == pdata.ValueTypeString && mp.bodyFilters != nil && mp.bodyFilters.Matches(lr.Body().StringVal()) {
return true
}

Expand Down
8 changes: 8 additions & 0 deletions internal/coreinternal/processor/filterlog/filterlog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,18 @@ func TestLogRecord_Matching_True(t *testing.T) {
},
},
},
{
name: "log_body_regexp_match",
properties: &filterconfig.MatchProperties{
Config: *createConfig(filterset.Regexp),
LogBodies: []string{"AUTH.*"},
},
},
}

lr := pdata.NewLogRecord()
lr.Attributes().InsertString("abc", "def")
lr.Body().SetStringVal("AUTHENTICATION FAILED")

for _, tc := range testcases {
t.Run(tc.name, func(t *testing.T) {
Expand Down
6 changes: 3 additions & 3 deletions processor/attributesprocessor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,13 @@ if the input data should be included or excluded from the processor. To configur
this option, under `include` and/or `exclude` at least `match_type` and one of the following
is required:
- For spans, one of `services`, `span_names`, `attributes`, `resources`, or `libraries` must be specified
with a non-empty value for a valid configuration. The `log_names`, `expressions`, `resource_attributes` and
with a non-empty value for a valid configuration. The `log_names`, `log_bodies`, `expressions`, `resource_attributes` and
`metric_names` fields are invalid.
- For logs, one of `log_names`, `attributes`, `resources`, or `libraries` must be specified with a
- For logs, one of `log_names`, `log_bodies`, `attributes`, `resources`, or `libraries` must be specified with a
non-empty value for a valid configuration. The `span_names`, `metric_names`, `expressions`, `resource_attributes`,
and `services` fields are invalid.
- For metrics, one of `metric_names`, `resources` must be specified
with a valid non-empty value for a valid configuration. The `span_names`, `log_names`, and
with a valid non-empty value for a valid configuration. The `span_names`, `log_names`, `log_bodies` and
`services` fields are invalid.


Expand Down
18 changes: 18 additions & 0 deletions processor/attributesprocessor/testdata/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,24 @@ processors:
action: update
value: "SELECT * FROM USERS [obfuscated]"


# The following demonstrates how to process logs that have a body that match regexp
# patterns. This processor will remove "token" attribute and will obfuscate "password"
# attribute in spans where body matches "AUTH.*".
attributes/log_body_regexp:
# Specifies the span properties that must exist for the processor to be applied.
include:
# match_type defines that "services" is an array of regexp-es.
match_type: regexp
# The span service name must match "auth.*" pattern.
log_bodies: ["AUTH.*"]
actions:
- key: password
action: update
value: "obfuscated"
- key: token
action: delete

receivers:
nop:

Expand Down

0 comments on commit 1a298d0

Please sign in to comment.