Skip to content

Commit

Permalink
export Links in Jaeger exporter. (#173)
Browse files Browse the repository at this point in the history
  • Loading branch information
paivagustavo authored and rghetia committed Oct 7, 2019
1 parent b1bb19a commit ab58cae
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 12 deletions.
25 changes: 13 additions & 12 deletions exporter/trace/jaeger/jaeger.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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,
}
}

Expand Down
21 changes: 21 additions & 0 deletions exporter/trace/jaeger/jaeger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import (
"testing"
"time"

apitrace "go.opentelemetry.io/api/trace"

"github.com/google/go-cmp/cmp"
"google.golang.org/grpc/codes"

Expand All @@ -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)
Expand All @@ -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"},
Expand Down Expand Up @@ -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.
},
},
Expand Down

0 comments on commit ab58cae

Please sign in to comment.