diff --git a/model/adjuster/span_id_deduper_test.go b/model/adjuster/span_id_deduper_test.go index 162823a9027..d9408744a8e 100644 --- a/model/adjuster/span_id_deduper_test.go +++ b/model/adjuster/span_id_deduper_test.go @@ -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()), }, }, { @@ -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) @@ -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") +}