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

[v2][adjuster] Add warning to span links adjuster #6381

Merged
merged 3 commits into from
Dec 18, 2024
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
8 changes: 8 additions & 0 deletions cmd/query/app/querysvc/adjuster/spanlinks.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ package adjuster

import (
"go.opentelemetry.io/collector/pdata/ptrace"

"github.com/jaegertracing/jaeger/internal/jptrace"
)

const (
invalidSpanLinkWarning = "Invalid span link removed"
)

// SpanLinks creates an adjuster that removes span links with empty trace IDs.
Expand Down Expand Up @@ -40,6 +46,8 @@ func (la LinksAdjuster) adjust(span ptrace.Span) {
if la.valid(link) {
newLink := validLinks.AppendEmpty()
link.CopyTo(newLink)
} else {
jptrace.AddWarning(span, invalidSpanLinkWarning)
}
}
validLinks.CopyTo(span.Links())
Expand Down
33 changes: 24 additions & 9 deletions cmd/query/app/querysvc/adjuster/spanlinks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/pdata/pcommon"
"go.opentelemetry.io/collector/pdata/ptrace"

"github.com/jaegertracing/jaeger/internal/jptrace"
)

func TestLinksAdjuster(t *testing.T) {
Expand All @@ -21,19 +23,32 @@ func TestLinksAdjuster(t *testing.T) {
scopeSpans.Spans().AppendEmpty()

// span with empty traceID link
spanA := scopeSpans.Spans().AppendEmpty()
spanA.Links().AppendEmpty().SetTraceID(pcommon.NewTraceIDEmpty())
spanB := scopeSpans.Spans().AppendEmpty()
spanB.Links().AppendEmpty().SetTraceID(pcommon.NewTraceIDEmpty())

// span with 2 non-empty traceID links and 1 empty (or zero) traceID link
spanB := scopeSpans.Spans().AppendEmpty()
spanB.Links().AppendEmpty().SetTraceID(pcommon.TraceID([]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}))
spanB.Links().AppendEmpty().SetTraceID(pcommon.TraceID([]byte{0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0}))
spanB.Links().AppendEmpty().SetTraceID(pcommon.TraceID([]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}))
spanC := scopeSpans.Spans().AppendEmpty()
spanC.Links().AppendEmpty().SetTraceID(pcommon.TraceID([]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}))
spanC.Links().AppendEmpty().SetTraceID(pcommon.TraceID([]byte{0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0}))
spanC.Links().AppendEmpty().SetTraceID(pcommon.TraceID([]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}))

err := SpanLinks().Adjust(traces)
spans := traces.ResourceSpans().At(0).ScopeSpans().At(0).Spans()
require.NoError(t, err)
assert.Equal(t, 0, spans.At(0).Links().Len())
assert.Equal(t, 0, spans.At(1).Links().Len())
assert.Equal(t, 2, spans.At(2).Links().Len())

gotSpansA := spans.At(0)
assert.Equal(t, 0, gotSpansA.Links().Len())
assert.Empty(t, jptrace.GetWarnings(gotSpansA))

gotSpansB := spans.At(1)
assert.Equal(t, 0, gotSpansB.Links().Len())
spanBWarnings := jptrace.GetWarnings(gotSpansB)
assert.Len(t, spanBWarnings, 1)
assert.Equal(t, "Invalid span link removed", spanBWarnings[0])

gotSpansC := spans.At(2)
assert.Equal(t, 2, gotSpansC.Links().Len())
spanCWarnings := jptrace.GetWarnings(gotSpansC)
assert.Len(t, spanCWarnings, 1)
assert.Equal(t, "Invalid span link removed", spanCWarnings[0])
}
Loading