Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[zipkin] Replace OT constants with OTEL #4625

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 19 additions & 13 deletions model/converter/thrift/zipkin/to_domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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.
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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
}
31 changes: 18 additions & 13 deletions model/converter/thrift/zipkin/to_domain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -116,27 +115,33 @@ 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": [
{"value": "cs", "host": {"service_name": "bar", "ipv4": 23456}},
{"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": [
{"value": "sr", "host": {"service_name": "bar", "ipv4": 23456}},
{"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,
},
}

Expand All @@ -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)
}
}

Expand Down