From 910520c1e2e6bfadca21078bc37de836662b2a4c Mon Sep 17 00:00:00 2001 From: Mahad Zaryab Date: Tue, 17 Dec 2024 15:01:59 -0500 Subject: [PATCH 1/2] Add Warning For Invalid Span Link Signed-off-by: Mahad Zaryab --- cmd/query/app/querysvc/adjuster/spanlinks.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/cmd/query/app/querysvc/adjuster/spanlinks.go b/cmd/query/app/querysvc/adjuster/spanlinks.go index d58ad63ab39..b90f41900ac 100644 --- a/cmd/query/app/querysvc/adjuster/spanlinks.go +++ b/cmd/query/app/querysvc/adjuster/spanlinks.go @@ -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. @@ -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()) From 19db66793930dece37a20b85e0dcb995528aea7e Mon Sep 17 00:00:00 2001 From: Mahad Zaryab Date: Tue, 17 Dec 2024 15:04:18 -0500 Subject: [PATCH 2/2] Update Unit Tests Signed-off-by: Mahad Zaryab --- .../app/querysvc/adjuster/spanlinks_test.go | 33 ++++++++++++++----- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/cmd/query/app/querysvc/adjuster/spanlinks_test.go b/cmd/query/app/querysvc/adjuster/spanlinks_test.go index af687e50bc4..7dfaf0ac6a6 100644 --- a/cmd/query/app/querysvc/adjuster/spanlinks_test.go +++ b/cmd/query/app/querysvc/adjuster/spanlinks_test.go @@ -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) { @@ -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]) }