Skip to content

Commit

Permalink
Add Test For Invalid Key With Non String Attribute
Browse files Browse the repository at this point in the history
Signed-off-by: Mahad Zaryab <[email protected]>
  • Loading branch information
mahadzaryab1 committed Oct 12, 2024
1 parent 13f6f82 commit bf3f7ad
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cmd/jaeger/internal/sanitizer/utf8.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func sanitizeAttributes(attributes pcommon.Map) {
case pcommon.ValueTypeBytes:
sanitized = append(sanitized, v.Bytes().AsRaw()...)
default:
sanitized = append(sanitized, []byte(v.Str())...)
sanitized = append(sanitized, []byte(v.AsString())...)
}

attributes.Remove(k)
Expand Down
19 changes: 19 additions & 0 deletions cmd/jaeger/internal/sanitizer/utf8_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,3 +229,22 @@ func TestUTF8Sanitizer_DoesNotSanitizeNonStringAttributeValue(t *testing.T) {
require.True(t, ok)
require.EqualValues(t, 1, value.Int())
}

func TestUTF8Sanitizer_SanitizesNonStringAttributeValueWithInvalidKey(t *testing.T) {
traces := ptrace.NewTraces()
traces.
ResourceSpans().
AppendEmpty().
Resource().
Attributes().PutInt(invalidUTF8(), 1)
sanitizer := NewUTF8Sanitizer()
sanitized := sanitizer(traces)
value, ok := sanitized.
ResourceSpans().
At(0).
Resource().
Attributes().
Get("invalid-tag-key")
require.True(t, ok)
require.EqualValues(t, getBytesValueFromString(fmt.Sprintf("%s:1", invalidUTF8())), value)
}

0 comments on commit bf3f7ad

Please sign in to comment.