From 679fb6ff772ef39fc91cf1e10860fe58cc3671ce Mon Sep 17 00:00:00 2001 From: Felipe Lopes Date: Tue, 11 Feb 2025 15:43:05 -0300 Subject: [PATCH] undo zipkin changes --- .../zipkin/zipkinv2/to_translator.go | 5 +- .../zipkin/zipkinv2/to_translator_test.go | 162 ------------------ 2 files changed, 2 insertions(+), 165 deletions(-) diff --git a/pkg/translator/zipkin/zipkinv2/to_translator.go b/pkg/translator/zipkin/zipkinv2/to_translator.go index 526599b471e6..53abad9653d0 100644 --- a/pkg/translator/zipkin/zipkinv2/to_translator.go +++ b/pkg/translator/zipkin/zipkinv2/to_translator.go @@ -128,7 +128,7 @@ func zSpanToInternal(zspan *zipkinmodel.SpanModel, tags map[string]string, dest dest.SetKind(zipkinKindToSpanKind(zspan.Kind, tags)) populateSpanStatus(tags, dest.Status()) - if err := TagsToSpanLinks(tags, dest.Links()); err != nil { + if err := zTagsToSpanLinks(tags, dest.Links()); err != nil { return err } @@ -183,8 +183,7 @@ func zipkinKindToSpanKind(kind zipkinmodel.Kind, tags map[string]string) ptrace. } } -// TagsToSpanLinks translates span tags into ptrace.SpanLinkSlice. -func TagsToSpanLinks(tags map[string]string, dest ptrace.SpanLinkSlice) error { +func zTagsToSpanLinks(tags map[string]string, dest ptrace.SpanLinkSlice) error { for i := 0; i < 128; i++ { key := fmt.Sprintf("otlp.link.%d", i) val, ok := tags[key] diff --git a/pkg/translator/zipkin/zipkinv2/to_translator_test.go b/pkg/translator/zipkin/zipkinv2/to_translator_test.go index 6edad3c05c3e..c037ee1bcd3e 100644 --- a/pkg/translator/zipkin/zipkinv2/to_translator_test.go +++ b/pkg/translator/zipkin/zipkinv2/to_translator_test.go @@ -4,14 +4,11 @@ package zipkinv2 import ( - "encoding/hex" - "strconv" "testing" "time" zipkinmodel "github.com/openzipkin/zipkin-go/model" "github.com/stretchr/testify/assert" - "go.opentelemetry.io/collector/pdata/pcommon" "go.opentelemetry.io/collector/pdata/ptrace" conventions "go.opentelemetry.io/collector/semconv/v1.6.1" @@ -265,162 +262,3 @@ func TestV2SpanWithoutTimestampGetsTag(t *testing.T) { assert.True(t, mapContainedKey) assert.True(t, wasAbsent.Bool()) } - -func TestTagsToSpanLinks(t *testing.T) { - tests := []struct { - name string - tags map[string]string - expectedLinks []ptrace.SpanLink - expectedError bool - }{ - { - name: "Single valid link", - tags: map[string]string{ - "otlp.link.0": "0102030405060708090a0b0c0d0e0f10|0102030405060708|state|{\"attr1\":\"value1\",\"attr2\":123}|0", - }, - expectedLinks: []ptrace.SpanLink{ - func() ptrace.SpanLink { - link := ptrace.NewSpanLink() - traceID, _ := hex.DecodeString("0102030405060708090a0b0c0d0e0f10") - link.SetTraceID(pcommon.TraceID(traceID)) - spanID, _ := hex.DecodeString("0102030405060708") - link.SetSpanID(pcommon.SpanID(spanID)) - link.TraceState().FromRaw("state") - attrs := link.Attributes() - attrs.PutStr("attr1", "value1") - attrs.PutInt("attr2", 123) - link.SetDroppedAttributesCount(0) - return link - }(), - }, - expectedError: false, - }, - { - name: "Multiple valid links", - tags: map[string]string{ - "otlp.link.0": "0102030405060708090a0b0c0d0e0f10|0102030405060708|state1|{\"attr1\":\"value1\"}|0", - "otlp.link.1": "1112131415161718191a1b1c1d1e1f20|1112131415161718|state2|{\"attr2\":456}|1", - }, - expectedLinks: []ptrace.SpanLink{ - func() ptrace.SpanLink { - link := ptrace.NewSpanLink() - traceID, _ := hex.DecodeString("0102030405060708090a0b0c0d0e0f10") - link.SetTraceID(pcommon.TraceID(traceID)) - spanID, _ := hex.DecodeString("0102030405060708") - link.SetSpanID(pcommon.SpanID(spanID)) - link.TraceState().FromRaw("state1") - attrs := link.Attributes() - attrs.PutStr("attr1", "value1") - link.SetDroppedAttributesCount(0) - return link - }(), - func() ptrace.SpanLink { - link := ptrace.NewSpanLink() - traceID, _ := hex.DecodeString("1112131415161718191a1b1c1d1e1f20") - link.SetTraceID(pcommon.TraceID(traceID)) - spanID, _ := hex.DecodeString("1112131415161718") - link.SetSpanID(pcommon.SpanID(spanID)) - link.TraceState().FromRaw("state2") - attrs := link.Attributes() - attrs.PutInt("attr2", 456) - link.SetDroppedAttributesCount(1) - return link - }(), - }, - expectedError: false, - }, - { - name: "Invalid format (too few parts)", - tags: map[string]string{ - "otlp.link.0": "invalid|value", - }, - expectedLinks: []ptrace.SpanLink{}, - expectedError: false, - }, - { - name: "Invalid hex in trace ID", - tags: map[string]string{ - "otlp.link.0": "nothex|0102030405060708|state|{\"attr1\":\"value1\"}|0", - }, - expectedLinks: nil, - expectedError: true, - }, - { - name: "Invalid dropped attributes count", - tags: map[string]string{ - "otlp.link.0": "0102030405060708090a0b0c0d0e0f10|0102030405060708|state|{\"attr1\":\"value1\"}|notanumber", - }, - expectedLinks: nil, - expectedError: true, - }, - { - name: "Attributes with pipe character", - tags: map[string]string{ - "otlp.link.0": "0102030405060708090a0b0c0d0e0f10|0102030405060708|state|{\"attr1\":\"value1|with|pipes\"}|0", - }, - expectedLinks: []ptrace.SpanLink{ - func() ptrace.SpanLink { - link := ptrace.NewSpanLink() - traceID, _ := hex.DecodeString("0102030405060708090a0b0c0d0e0f10") - link.SetTraceID(pcommon.TraceID(traceID)) - spanID, _ := hex.DecodeString("0102030405060708") - link.SetSpanID(pcommon.SpanID(spanID)) - link.TraceState().FromRaw("state") - attrs := link.Attributes() - attrs.PutStr("attr1", "value1|with|pipes") - link.SetDroppedAttributesCount(0) - return link - }(), - }, - expectedError: false, - }, - { - name: "No links in tags", - tags: map[string]string{}, - expectedLinks: []ptrace.SpanLink{}, - expectedError: false, - }, - } - - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - dest := ptrace.NewSpanLinkSlice() - err := TagsToSpanLinks(tt.tags, dest) - if tt.expectedError { - assert.Error(t, err) - return - } - assert.NoError(t, err) - assert.Equal(t, len(tt.expectedLinks), dest.Len()) - - for i, expected := range tt.expectedLinks { - link := dest.At(i) - - assert.Equal(t, expected.TraceID(), link.TraceID(), "TraceID mismatch") - assert.Equal(t, expected.SpanID(), link.SpanID(), "SpanID mismatch") - assert.Equal(t, expected.TraceState().AsRaw(), link.TraceState().AsRaw()) - - assert.Equal(t, expected.DroppedAttributesCount(), link.DroppedAttributesCount()) - - // Verify attributes - expectedAttrs := expected.Attributes() - actualAttrs := link.Attributes() - assert.Equal(t, expectedAttrs.Len(), actualAttrs.Len(), "Attributes length mismatch") - - expectedAttrs.Range(func(k string, v pcommon.Value) bool { - actualVal, ok := actualAttrs.Get(k) - assert.True(t, ok, "Attribute %s not found in link", k) - assert.Equal(t, v, actualVal, "Attribute %s value mismatch", k) - return true - }) - } - - // Verify that link tags are removed - for i := 0; i < 128; i++ { - key := "otlp.link." + strconv.Itoa(i) - _, ok := tt.tags[key] - assert.False(t, ok, "Expected tag %s to be deleted", key) - } - }) - } -}