diff --git a/model/converter/thrift/zipkin/to_domain.go b/model/converter/thrift/zipkin/to_domain.go index 0ee67e5a6ad..f4dd3655f74 100644 --- a/model/converter/thrift/zipkin/to_domain.go +++ b/model/converter/thrift/zipkin/to_domain.go @@ -23,7 +23,7 @@ import ( "errors" "fmt" - "github.com/opentracing/opentracing-go/ext" + "go.opentelemetry.io/otel/trace" "github.com/jaegertracing/jaeger/model" "github.com/jaegertracing/jaeger/thrift-gen/zipkincore" @@ -32,14 +32,20 @@ import ( const ( // UnknownServiceName is serviceName we give to model.Process if we cannot find it anywhere in a Zipkin span UnknownServiceName = "unknown-service-name" + keySpanKind = "span.kind" + component = "component" + peerservice = "peer.service" + peerHostIPv4 = "peer.ipv4" + peerHostIPv6 = "peer.ipv6" + peerPort = "peer.port" ) var ( coreAnnotations = map[string]string{ - zipkincore.SERVER_RECV: string(ext.SpanKindRPCServerEnum), - zipkincore.SERVER_SEND: string(ext.SpanKindRPCServerEnum), - zipkincore.CLIENT_RECV: string(ext.SpanKindRPCClientEnum), - zipkincore.CLIENT_SEND: string(ext.SpanKindRPCClientEnum), + zipkincore.SERVER_RECV: trace.SpanKindServer.String(), + zipkincore.SERVER_SEND: trace.SpanKindServer.String(), + zipkincore.CLIENT_RECV: trace.SpanKindClient.String(), + zipkincore.CLIENT_SEND: trace.SpanKindClient.String(), } // Some tags on Zipkin spans really describe the process emitting them rather than an individual span. @@ -165,13 +171,13 @@ func (td toDomain) transformSpan(zSpan *zipkincore.Span) []*model.Span { } // if the first span is a client span we create server span and vice-versa. if result[0].IsRPCClient() { - s.Tags = []model.KeyValue{model.String(string(ext.SpanKind), string(ext.SpanKindRPCServerEnum))} + s.Tags = []model.KeyValue{model.String(keySpanKind, trace.SpanKindServer.String())} s.StartTime = model.EpochMicrosecondsAsTime(uint64(sr.Timestamp)) if ss := td.findAnnotation(zSpan, zipkincore.SERVER_SEND); ss != nil { s.Duration = model.MicrosecondsAsDuration(uint64(ss.Timestamp - sr.Timestamp)) } } else { - s.Tags = []model.KeyValue{model.String(string(ext.SpanKind), string(ext.SpanKindRPCClientEnum))} + s.Tags = []model.KeyValue{model.String(keySpanKind, trace.SpanKindClient.String())} s.StartTime = model.EpochMicrosecondsAsTime(uint64(cs.Timestamp)) if cr := td.findAnnotation(zSpan, zipkincore.CLIENT_RECV); cr != nil { s.Duration = model.MicrosecondsAsDuration(uint64(cr.Timestamp - cs.Timestamp)) @@ -286,7 +292,7 @@ func (td toDomain) getTags(binAnnotations []*zipkincore.BinaryAnnotation, tagInc switch annotation.Key { case zipkincore.LOCAL_COMPONENT: value := string(annotation.Value) - tag := model.String(string(ext.Component), value) + tag := model.String(component, value) retMe = append(retMe, tag) case zipkincore.SERVER_ADDR, zipkincore.CLIENT_ADDR, zipkincore.MESSAGE_ADDR: retMe = td.getPeerTags(annotation.Host, retMe) @@ -385,7 +391,7 @@ func (td toDomain) getLogFields(annotation *zipkincore.Annotation) []model.KeyVa func (td toDomain) getSpanKindTag(annotations []*zipkincore.Annotation) (model.KeyValue, bool) { for _, a := range annotations { if spanKind, ok := coreAnnotations[a.Value]; ok { - return model.String(string(ext.SpanKind), spanKind), true + return model.String(keySpanKind, spanKind), true } } return model.KeyValue{}, false @@ -395,19 +401,19 @@ func (td toDomain) getPeerTags(endpoint *zipkincore.Endpoint, tags []model.KeyVa if endpoint == nil { return tags } - tags = append(tags, model.String(string(ext.PeerService), endpoint.ServiceName)) + tags = append(tags, model.String(peerservice, endpoint.ServiceName)) if endpoint.Ipv4 != 0 { ipv4 := int64(uint32(endpoint.Ipv4)) - tags = append(tags, model.Int64(string(ext.PeerHostIPv4), ipv4)) + tags = append(tags, model.Int64(peerHostIPv4, ipv4)) } if endpoint.Ipv6 != nil { // Zipkin defines Ipv6 field as: "IPv6 host address packed into 16 bytes. Ex Inet6Address.getBytes()". // https://github.com/openzipkin/zipkin-api/blob/master/thrift/zipkinCore.thrift#L305 - tags = append(tags, model.Binary(string(ext.PeerHostIPv6), endpoint.Ipv6)) + tags = append(tags, model.Binary(peerHostIPv6, endpoint.Ipv6)) } if endpoint.Port != 0 { port := int64(uint16(endpoint.Port)) - tags = append(tags, model.Int64(string(ext.PeerPort), port)) + tags = append(tags, model.Int64(peerPort, port)) } return tags } diff --git a/model/converter/thrift/zipkin/to_domain_test.go b/model/converter/thrift/zipkin/to_domain_test.go index f8589fcddc7..865f59ea554 100644 --- a/model/converter/thrift/zipkin/to_domain_test.go +++ b/model/converter/thrift/zipkin/to_domain_test.go @@ -29,10 +29,9 @@ import ( "github.com/gogo/protobuf/jsonpb" "github.com/gogo/protobuf/proto" "github.com/kr/pretty" - "github.com/opentracing/opentracing-go" - "github.com/opentracing/opentracing-go/ext" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.opentelemetry.io/otel/trace" "github.com/jaegertracing/jaeger/model" z "github.com/jaegertracing/jaeger/thrift-gen/zipkincore" @@ -116,9 +115,11 @@ func TestToDomainWithDurationFromClientAnnotations(t *testing.T) { func TestToDomainMultipleSpanKinds(t *testing.T) { tests := []struct { - json string - tagFirst opentracing.Tag - tagSecond opentracing.Tag + json string + tagFirstKey string + tagSecondKey string + tagFirstVal trace.SpanKind + tagSecondVal trace.SpanKind }{ { json: `[{ "trace_id": -1, "id": 31, "annotations": [ @@ -126,8 +127,10 @@ func TestToDomainMultipleSpanKinds(t *testing.T) { {"value": "sr", "timestamp": 1, "host": {"service_name": "bar", "ipv4": 23456}}, {"value": "ss", "timestamp": 2, "host": {"service_name": "bar", "ipv4": 23456}} ]}]`, - tagFirst: ext.SpanKindRPCClient, - tagSecond: ext.SpanKindRPCServer, + tagFirstKey: keySpanKind, + tagSecondKey: keySpanKind, + tagFirstVal: trace.SpanKindClient, + tagSecondVal: trace.SpanKindServer, }, { json: `[{ "trace_id": -1, "id": 31, "annotations": [ @@ -135,8 +138,10 @@ func TestToDomainMultipleSpanKinds(t *testing.T) { {"value": "cs", "timestamp": 1, "host": {"service_name": "bar", "ipv4": 23456}}, {"value": "cr", "timestamp": 2, "host": {"service_name": "bar", "ipv4": 23456}} ]}]`, - tagFirst: ext.SpanKindRPCServer, - tagSecond: ext.SpanKindRPCClient, + tagFirstKey: keySpanKind, + tagSecondKey: keySpanKind, + tagFirstVal: trace.SpanKindServer, + tagSecondVal: trace.SpanKindClient, }, } @@ -146,13 +151,13 @@ func TestToDomainMultipleSpanKinds(t *testing.T) { assert.Equal(t, 2, len(trace.Spans)) assert.Equal(t, 1, len(trace.Spans[0].Tags)) - assert.Equal(t, test.tagFirst.Key, trace.Spans[0].Tags[0].Key) - assert.Equal(t, string(test.tagFirst.Value.(ext.SpanKindEnum)), trace.Spans[0].Tags[0].VStr) + assert.Equal(t, test.tagFirstKey, trace.Spans[0].Tags[0].Key) + assert.Equal(t, test.tagFirstVal.String(), trace.Spans[0].Tags[0].VStr) assert.Equal(t, 1, len(trace.Spans[1].Tags)) - assert.Equal(t, test.tagSecond.Key, trace.Spans[1].Tags[0].Key) + assert.Equal(t, test.tagSecondKey, trace.Spans[1].Tags[0].Key) assert.Equal(t, time.Duration(1000), trace.Spans[1].Duration) - assert.Equal(t, string(test.tagSecond.Value.(ext.SpanKindEnum)), trace.Spans[1].Tags[0].VStr) + assert.Equal(t, test.tagSecondVal.String(), trace.Spans[1].Tags[0].VStr) } }