Skip to content

Commit

Permalink
Merge branch 'main' into ui-tracing
Browse files Browse the repository at this point in the history
  • Loading branch information
mahadzaryab1 authored Dec 18, 2024
2 parents c26dc80 + 7fdb6e9 commit db586ba
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
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])
}

0 comments on commit db586ba

Please sign in to comment.