Skip to content

Commit 241f965

Browse files
[processor][redaction]: redact span event attributes (#38288)
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description Fix redaction processor to redact span event attributes as well. <!-- Issue number (e.g. #1234) or full URL to issue, if applicable. --> #### Link to tracking issue Fixes #36633 <!--Describe what testing was performed and which tests were added.--> #### Testing Added <!--Describe the documentation added.--> #### Documentation <!--Please delete paragraphs that you did not use before submitting.--> Co-authored-by: Dmitrii Anoshin <[email protected]>
1 parent a7be72f commit 241f965

File tree

3 files changed

+75
-0
lines changed

3 files changed

+75
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: bug_fix
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
7+
component: redactionprocessor
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Fix redaction processor to redact span event attributes
11+
12+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
13+
issues: [36633]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext:
19+
20+
# If your change doesn't affect end users or the exported elements of any package,
21+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
22+
# Optional: The change log or logs in which this entry should be included.
23+
# e.g. '[user]' or '[user, api]'
24+
# Include 'user' if the change is relevant to end users.
25+
# Include 'api' if there is a change to a library API.
26+
# Default: '[user]'
27+
change_logs: []

processor/redactionprocessor/processor.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,19 @@ func (s *redaction) processResourceSpan(ctx context.Context, rs ptrace.ResourceS
110110

111111
// Attributes can also be part of span
112112
s.processAttrs(ctx, spanAttrs)
113+
114+
// Attributes can also be part of span events
115+
s.processSpanEvents(ctx, span.Events())
113116
}
114117
}
115118
}
116119

120+
func (s *redaction) processSpanEvents(ctx context.Context, events ptrace.SpanEventSlice) {
121+
for i := 0; i < events.Len(); i++ {
122+
s.processAttrs(ctx, events.At(i).Attributes())
123+
}
124+
}
125+
117126
// processResourceLog processes the log resource and all of its logs and then returns the last
118127
// view metric context. The context can be used for tests
119128
func (s *redaction) processResourceLog(ctx context.Context, rl plog.ResourceLogs) {

processor/redactionprocessor/processor_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,45 @@ func TestProcessAttrsAppliedTwice(t *testing.T) {
567567
assert.Equal(t, int64(2), val.Int())
568568
}
569569

570+
func TestSpanEventRedacted(t *testing.T) {
571+
inBatch := ptrace.NewTraces()
572+
rs := inBatch.ResourceSpans().AppendEmpty()
573+
ils := rs.ScopeSpans().AppendEmpty()
574+
575+
library := ils.Scope()
576+
library.SetName("first-library")
577+
span := ils.Spans().AppendEmpty()
578+
span.SetName("first-batch-first-span")
579+
span.SetTraceID([16]byte{1, 2, 3, 4})
580+
581+
event := span.Events().AppendEmpty()
582+
event.SetName("event-one")
583+
584+
event.Attributes().PutStr("password", "xyzxyz")
585+
event.Attributes().PutStr("username", "foobar")
586+
587+
config := &Config{
588+
AllowAllKeys: true,
589+
BlockedValues: []string{"xyzxyz"},
590+
Summary: "debug",
591+
}
592+
processor, err := newRedaction(context.TODO(), config, zaptest.NewLogger(t))
593+
require.NoError(t, err)
594+
595+
outTraces, err := processor.processTraces(context.TODO(), inBatch)
596+
require.NoError(t, err)
597+
598+
attr := outTraces.ResourceSpans().At(0).ScopeSpans().At(0).Spans().At(0).Events().At(0).Attributes()
599+
600+
val, ok := attr.Get("password")
601+
require.True(t, ok)
602+
assert.Equal(t, "****", val.Str())
603+
604+
val, ok = attr.Get("username")
605+
require.True(t, ok)
606+
require.Equal(t, "foobar", val.Str())
607+
}
608+
570609
// runTest transforms the test input data and passes it through the processor
571610
func runTest(
572611
t *testing.T,

0 commit comments

Comments
 (0)