From ab58cae33bcb83cf204af6c496ea4055407ddaad Mon Sep 17 00:00:00 2001 From: Gustavo Silva Paiva Date: Mon, 7 Oct 2019 13:40:36 -0300 Subject: [PATCH] export Links in Jaeger exporter. (#173) --- exporter/trace/jaeger/jaeger.go | 25 +++++++++++++------------ exporter/trace/jaeger/jaeger_test.go | 21 +++++++++++++++++++++ 2 files changed, 34 insertions(+), 12 deletions(-) diff --git a/exporter/trace/jaeger/jaeger.go b/exporter/trace/jaeger/jaeger.go index 14a1f882c49..51ed9002a80 100644 --- a/exporter/trace/jaeger/jaeger.go +++ b/exporter/trace/jaeger/jaeger.go @@ -182,16 +182,18 @@ func spanDataToThrift(data *trace.SpanData) *gen.Span { Fields: fields, }) } - //TODO: [rghetia] add links. - // - //var refs []*gen.SpanRef - //for _, link := range data.Links { - // refs = append(refs, &gen.SpanRef{ - // TraceIdHigh: bytesToInt64(link.TraceID[0:8]), - // TraceIdLow: bytesToInt64(link.TraceID[8:16]), - // SpanId: bytesToInt64(link.SpanID[:]), - // }) - //} + + var refs []*gen.SpanRef + for _, link := range data.Links { + refs = append(refs, &gen.SpanRef{ + TraceIdHigh: int64(link.TraceID.High), + TraceIdLow: int64(link.TraceID.Low), + SpanId: int64(link.SpanID), + // TODO(paivagustavo): properly set the reference type when specs are defined + // see https://github.com/open-telemetry/opentelemetry-specification/issues/65 + RefType: gen.SpanRefType_CHILD_OF, + }) + } return &gen.Span{ TraceIdHigh: int64(data.SpanContext.TraceID.High), @@ -204,8 +206,7 @@ func spanDataToThrift(data *trace.SpanData) *gen.Span { Duration: data.EndTime.Sub(data.StartTime).Nanoseconds() / 1000, Tags: tags, Logs: logs, - // TODO: goes with Links. - // References: refs, + References: refs, } } diff --git a/exporter/trace/jaeger/jaeger_test.go b/exporter/trace/jaeger/jaeger_test.go index 256041bfe3b..3e97a71ac23 100644 --- a/exporter/trace/jaeger/jaeger_test.go +++ b/exporter/trace/jaeger/jaeger_test.go @@ -19,6 +19,8 @@ import ( "testing" "time" + apitrace "go.opentelemetry.io/api/trace" + "github.com/google/go-cmp/cmp" "google.golang.org/grpc/codes" @@ -34,6 +36,9 @@ func Test_spanDataToThrift(t *testing.T) { traceID := core.TraceID{High: 0x0102030405060708, Low: 0x090a0b0c0d0e0f10} spanID := uint64(0x0102030405060708) + linkTraceID := core.TraceID{High: 0x0102030405060709, Low: 0x090a0b0c0d0e0f11} + linkSpanID := uint64(0x0102030405060709) + keyValue := "value" statusCodeValue := int64(2) doubleValue := float64(123.456) @@ -55,6 +60,14 @@ func Test_spanDataToThrift(t *testing.T) { Name: "/foo", StartTime: now, EndTime: now, + Links: []apitrace.Link{ + apitrace.Link{ + SpanContext: core.SpanContext{ + TraceID: linkTraceID, + SpanID: linkSpanID, + }, + }, + }, Attributes: []core.KeyValue{ { Key: core.Key{Name: "key"}, @@ -82,6 +95,14 @@ func Test_spanDataToThrift(t *testing.T) { {Key: "status.code", VType: gen.TagType_LONG, VLong: &statusCodeValue}, {Key: "status.message", VType: gen.TagType_STRING, VStr: &statusMessage}, }, + References: []*gen.SpanRef{ + &gen.SpanRef{ + RefType: gen.SpanRefType_CHILD_OF, + TraceIdLow: int64(linkTraceID.Low), + TraceIdHigh: int64(linkTraceID.High), + SpanId: int64(linkSpanID), + }, + }, // TODO [rghetia]: check Logs when event is added. }, },