Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[processor/transform] Fix panic when transforming span events #16622

Merged
merged 2 commits into from
Dec 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .chloggen/tp-fix-spanevent-bug.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: bug_fix

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: processor/transform

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Fix issue where collector would panic under certain conditions if the transformprocessor was configured to transform span events.

# One or more tracking issues related to the change
issues: [16622]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:
2 changes: 1 addition & 1 deletion processor/transformprocessor/internal/common/traces.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (s spanEventStatements) ConsumeTraces(ctx context.Context, td ptrace.Traces
span := spans.At(k)
spanEvents := span.Events()
for n := 0; n < spanEvents.Len(); n++ {
tCtx := ottlspanevent.NewTransformContext(spanEvents.At(k), span, sspans.Scope(), rspans.Resource())
tCtx := ottlspanevent.NewTransformContext(spanEvents.At(n), span, sspans.Scope(), rspans.Resource())
for _, statement := range s {
_, _, err := statement.Execute(ctx, tCtx)
if err != nil {
Expand Down
34 changes: 34 additions & 0 deletions processor/transformprocessor/internal/traces/processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,36 @@ func Test_ProcessTraces_TraceContext(t *testing.T) {
}
}

func Test_ProcessTraces_SpanEventContext(t *testing.T) {
tests := []struct {
statement string
want func(td ptrace.Traces)
}{
{
statement: `set(attributes["test"], "pass") where name == "eventA"`,
want: func(td ptrace.Traces) {
td.ResourceSpans().At(0).ScopeSpans().At(0).Spans().At(0).Events().At(0).Attributes().PutStr("test", "pass")
},
},
}

for _, tt := range tests {
t.Run(tt.statement, func(t *testing.T) {
td := constructTraces()
processor, err := NewProcessor(nil, []common.ContextStatements{{Context: "spanevent", Statements: []string{tt.statement}}}, componenttest.NewNopTelemetrySettings())
assert.NoError(t, err)

_, err = processor.ProcessTraces(context.Background(), td)
assert.NoError(t, err)

exTd := constructTraces()
tt.want(exTd)

assert.Equal(t, exTd, td)
})
}
}

func Test_ProcessTraces_MixContext(t *testing.T) {
tests := []struct {
name string
Expand Down Expand Up @@ -617,6 +647,8 @@ func fillSpanOne(span ptrace.Span) {
status := span.Status()
status.SetCode(ptrace.StatusCodeError)
status.SetMessage("status-cancelled")
event := span.Events().AppendEmpty()
event.SetName("eventA")
}

func fillSpanTwo(span ptrace.Span) {
Expand All @@ -635,4 +667,6 @@ func fillSpanTwo(span ptrace.Span) {
status := span.Status()
status.SetCode(ptrace.StatusCodeError)
status.SetMessage("status-cancelled")
event := span.Events().AppendEmpty()
event.SetName("eventB")
}