Skip to content

Commit

Permalink
OC Proto to Jaeger Thrift translation (#221)
Browse files Browse the repository at this point in the history
* OC Proto to Jaeger Thrift

* PR Feedback

* PR Feedbacl round #2

* Allow absence of ParentSpanId and better handle for other IDs
  • Loading branch information
Paulo Janotti committed Nov 28, 2018
1 parent 9b7718d commit d868a94
Show file tree
Hide file tree
Showing 10 changed files with 962 additions and 17 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/BurntSushi/toml v0.3.1 // indirect
github.com/DataDog/datadog-go v0.0.0-20180822151419-281ae9f2d895 // indirect
github.com/DataDog/opencensus-go-exporter-datadog v0.0.0-20181026070331-e7c4bd17b329
github.com/apache/thrift v0.0.0-20161221203622-b2a4d4ae21c7 // indirect
github.com/apache/thrift v0.0.0-20161221203622-b2a4d4ae21c7
github.com/aws/aws-sdk-go v1.15.68 // indirect
github.com/bmizerany/perks v0.0.0-20141205001514-d9a9656a3a4b // indirect
github.com/census-instrumentation/opencensus-proto v0.1.0
Expand Down Expand Up @@ -37,7 +37,7 @@ require (
github.com/stretchr/testify v1.2.2 // indirect
github.com/tinylib/msgp v1.0.2 // indirect
github.com/uber-go/atomic v1.3.2 // indirect
github.com/uber/jaeger-lib v1.5.0 // indirect
github.com/uber/jaeger-lib v1.5.0
github.com/uber/tchannel-go v1.10.0
github.com/yancl/opencensus-go-exporter-kafka v0.0.0-20181029030031-9c471c1bfbeb
go.opencensus.io v0.18.0
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NH
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/jaegertracing/jaeger v1.7.0 h1:RVpmOTj7Zb9QRFHI5CYvkYSTR8Cdn/PhM5kBxA4pZBM=
github.com/jaegertracing/jaeger v1.7.0/go.mod h1:LUWPSnzNPGRubM8pk0inANGitpiMOOxihXx0+53llXI=
github.com/jaegertracing/jaeger v1.8.0 h1:8nWwXtXFqCVyEPjKczfnB1Yj9s7DmaDHYbqnfNBORMY=
github.com/jmespath/go-jmespath v0.0.0-20160202185014-0b12d6b521d8 h1:12VvqtR6Aowv3l/EQUlocDHW2Cp4G9WJVH7uyH8QFJE=
github.com/jmespath/go-jmespath v0.0.0-20160202185014-0b12d6b521d8/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af h1:pmfjZENx5imkbgOkpRUYLnmbU7UEFbjtDA2hxJ1ichM=
Expand Down
28 changes: 24 additions & 4 deletions receiver/jaeger/trace_receiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func TestReception(t *testing.T) {
{
TraceID: trace.TraceID{0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF, 0x80},
SpanID: trace.SpanID{0xCF, 0xCE, 0xCD, 0xCC, 0xCB, 0xCA, 0xC9, 0xC8},
Type: trace.LinkTypeChild,
Type: trace.LinkTypeParent,
},
},
},
Expand All @@ -111,7 +111,7 @@ func TestReception(t *testing.T) {
{
TraceID: trace.TraceID{0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF, 0x80},
SpanID: trace.SpanID{0xAF, 0xAE, 0xAD, 0xAC, 0xAB, 0xAA, 0xA9, 0xA8},
Type: trace.LinkTypeParent,
Type: trace.LinkTypeChild,
},
},
},
Expand Down Expand Up @@ -154,12 +154,22 @@ func TestReception(t *testing.T) {
Code: trace.StatusCodeNotFound,
Message: "Stale indices",
},
Attributes: &tracepb.Span_Attributes{
AttributeMap: map[string]*tracepb.AttributeValue{
"status.code": {
Value: &tracepb.AttributeValue_IntValue{IntValue: trace.StatusCodeNotFound},
},
"status.message": {
Value: &tracepb.AttributeValue_StringValue{StringValue: &tracepb.TruncatableString{Value: "Stale indices"}},
},
},
},
Links: &tracepb.Span_Links{
Link: []*tracepb.Span_Link{
{
TraceId: []byte{0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF, 0x80},
SpanId: []byte{0xCF, 0xCE, 0xCD, 0xCC, 0xCB, 0xCA, 0xC9, 0xC8},
Type: tracepb.Span_Link_CHILD_LINKED_SPAN,
Type: tracepb.Span_Link_PARENT_LINKED_SPAN,
},
},
},
Expand All @@ -174,6 +184,16 @@ func TestReception(t *testing.T) {
Code: trace.StatusCodeInternal,
Message: "Frontend crash",
},
Attributes: &tracepb.Span_Attributes{
AttributeMap: map[string]*tracepb.AttributeValue{
"status.code": {
Value: &tracepb.AttributeValue_IntValue{IntValue: trace.StatusCodeInternal},
},
"status.message": {
Value: &tracepb.AttributeValue_StringValue{StringValue: &tracepb.TruncatableString{Value: "Frontend crash"}},
},
},
},
Links: &tracepb.Span_Links{
Link: []*tracepb.Span_Link{
{
Expand All @@ -184,7 +204,7 @@ func TestReception(t *testing.T) {
// * Child_of
// * Follows_from
// yet OpenCensus has Parent too but Jaeger uses a zero-value for LinkCHILD.
Type: tracepb.Span_Link_CHILD_LINKED_SPAN,
Type: tracepb.Span_Link_PARENT_LINKED_SPAN,
},
},
},
Expand Down
6 changes: 2 additions & 4 deletions translator/trace/jaegerthrift_to_protospan.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ func jReferencesToOCProtoLinks(jrefs []*jaeger.SpanRef) *tracepb.Span_Links {
for _, jref := range jrefs {
var linkType tracepb.Span_Link_Type
if jref.RefType == jaeger.SpanRefType_CHILD_OF {
linkType = tracepb.Span_Link_CHILD_LINKED_SPAN
// Wording on OC for Span_Link_PARENT_LINKED_SPAN: The linked span is a parent of the current span.
linkType = tracepb.Span_Link_PARENT_LINKED_SPAN
} else {
// TODO: SpanRefType_FOLLOWS_FROM doesn't map well to OC, so treat all other cases as unknown
linkType = tracepb.Span_Link_TYPE_UNSPECIFIED
Expand Down Expand Up @@ -227,15 +228,12 @@ func jtagsToAttributes(tags []*jaeger.Tag) (string, tracepb.Span_SpanKind, *trac
case "http.status_code", "status.code": // It is expected to be an int
statusCodePtr = new(int32)
*statusCodePtr = int32(tag.GetVLong())
continue

case "http.status_message", "status.message":
statusMessage = tag.GetVStr()
continue

case "message":
message = tag.GetVStr()
continue
}

attrib := &tracepb.AttributeValue{}
Expand Down
40 changes: 34 additions & 6 deletions translator/trace/jaegerthrift_to_protospan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ import (
"reflect"
"testing"

"github.com/census-instrumentation/opencensus-service/internal/testutils"
"github.com/jaegertracing/jaeger/thrift-gen/jaeger"

commonpb "github.com/census-instrumentation/opencensus-proto/gen-go/agent/common/v1"
agenttracepb "github.com/census-instrumentation/opencensus-proto/gen-go/agent/trace/v1"
tracepb "github.com/census-instrumentation/opencensus-proto/gen-go/trace/v1"
"github.com/jaegertracing/jaeger/thrift-gen/jaeger"
"github.com/census-instrumentation/opencensus-service/internal/testutils"
)

func TestJaegerThriftBatchToOCProto(t *testing.T) {
Expand Down Expand Up @@ -118,12 +118,12 @@ func TestConservativeConversions(t *testing.T) {
Tags: []*jaeger.Tag{
{
Key: "http.status_code",
VLong: func() *int64 { v := int64(5); return &v }(),
VLong: func() *int64 { v := int64(403); return &v }(),
VType: jaeger.TagType_LONG,
},
{
Key: "http.status_message",
VStr: func() *string { v := "cache miss"; return &v }(),
VStr: func() *string { v := "Forbidden"; return &v }(),
VType: jaeger.TagType_STRING,
},
},
Expand Down Expand Up @@ -205,8 +205,22 @@ func TestConservativeConversions(t *testing.T) {
TraceId: []byte{0x00, 0x11, 0x12, 0x13, 0x14, 0x11, 0x11, 0x11, 0x01, 0x11, 0x11, 0x11, 0xFF, 0xFF, 0xFF, 0xFF},
// Ensure that the status code was properly translated
Status: &tracepb.Status{
Code: 5,
Message: "cache miss",
Code: 403,
Message: "Forbidden",
},
Attributes: &tracepb.Span_Attributes{
AttributeMap: map[string]*tracepb.AttributeValue{
"http.status_code": {
Value: &tracepb.AttributeValue_IntValue{
IntValue: 403,
},
},
"http.status_message": {
Value: &tracepb.AttributeValue_StringValue{
StringValue: &tracepb.TruncatableString{Value: "Forbidden"},
},
},
},
},
},
{
Expand All @@ -217,6 +231,20 @@ func TestConservativeConversions(t *testing.T) {
Code: 13,
Message: "proxy crashed",
},
Attributes: &tracepb.Span_Attributes{
AttributeMap: map[string]*tracepb.AttributeValue{
"status.code": {
Value: &tracepb.AttributeValue_IntValue{
IntValue: 13,
},
},
"status.message": {
Value: &tracepb.AttributeValue_StringValue{
StringValue: &tracepb.TruncatableString{Value: "proxy crashed"},
},
},
},
},
},
},
},
Expand Down
Loading

0 comments on commit d868a94

Please sign in to comment.