1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2025-02-01 13:07:51 +02:00

export Links in Jaeger exporter. (#173)

This commit is contained in:
Gustavo Silva Paiva 2019-10-07 13:40:36 -03:00 committed by rghetia
parent b1bb19aa80
commit ab58cae33b
2 changed files with 34 additions and 12 deletions

View File

@ -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,
}
}

View File

@ -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.
},
},