Skip to content

Commit

Permalink
fix up span id dedupe testing
Browse files Browse the repository at this point in the history
  • Loading branch information
cdanis committed Sep 23, 2024
1 parent 888ca59 commit 225d255
Showing 1 changed file with 47 additions and 4 deletions.
51 changes: 47 additions & 4 deletions model/adjuster/span_id_deduper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ func newDuplicatedSpansTrace() *model.Trace {
TraceID: traceID,
SpanID: clientSpanID,
Tags: model.KeyValues{
// span.kind = client
model.String(keySpanKind, trace.SpanKindClient.String()),
// span.kind = server
model.String(keySpanKind, trace.SpanKindServer.String()),
},
},
{
Expand All @@ -46,8 +46,31 @@ func newDuplicatedSpansTrace() *model.Trace {
}
}

func TestDedupeBySpanID(t *testing.T) {
trace := newZipkinTrace()
func newUniqueSpansTrace() *model.Trace {
traceID := model.NewTraceID(0, 42)
return &model.Trace{
Spans: []*model.Span{
{
// server span
TraceID: traceID,
SpanID: clientSpanID,
Tags: model.KeyValues{
// span.kind = server
model.String(keySpanKind, trace.SpanKindServer.String()),
},
},
{
// some other span, child of server span
TraceID: traceID,
SpanID: anotherSpanID,
References: []model.SpanRef{model.NewChildOfRef(traceID, clientSpanID)},
},
},
}
}

func TestDedupeBySpanIDTriggers(t *testing.T) {
trace := newDuplicatedSpansTrace()
deduper := DedupeBySpanID()
trace, err := deduper.Adjust(trace)
require.NoError(t, err)
Expand All @@ -56,3 +79,23 @@ func TestDedupeBySpanID(t *testing.T) {
assert.Equal(t, clientSpanID, trace.Spans[0].SpanID, "client span should be kept")
assert.Equal(t, anotherSpanID, trace.Spans[1].SpanID, "3rd span should be kept")
}

func TestDedupeBySpanIDNotTriggered(t *testing.T) {
trace := newUniqueSpansTrace()
deduper := DedupeBySpanID()
trace, err := deduper.Adjust(trace)
require.NoError(t, err)

assert.Len(t, trace.Spans, 2, "should not dedupe spans")
assert.Equal(t, clientSpanID, trace.Spans[0].SpanID, "client span should be kept")
assert.Equal(t, anotherSpanID, trace.Spans[1].SpanID, "child span should be kept")
}

func TestDedupeBySpanIDEmpty(t *testing.T) {
trace := &model.Trace{}
deduper := DedupeBySpanID()
trace, err := deduper.Adjust(trace)
require.NoError(t, err)

assert.Len(t, trace.Spans, 0, "should be 0 spans")
}

0 comments on commit 225d255

Please sign in to comment.