Skip to content
This repository has been archived by the owner on Jul 31, 2023. It is now read-only.

avoid null pointer exception #11

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions jaeger.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ func spanDataToThrift(data *trace.SpanData) *jaeger.Span {
tags = append(tags, attributeToTag("error", true))
}

var logs []*jaeger.Log
logs := make([]*jaeger.Log, 0, len(data.Annotations))
for _, a := range data.Annotations {
fields := make([]*jaeger.Tag, 0, len(a.Attributes))
for k, v := range a.Attributes {
Expand All @@ -233,7 +233,7 @@ func spanDataToThrift(data *trace.SpanData) *jaeger.Span {
Fields: fields,
})
}
var refs []*jaeger.SpanRef
refs := make([]*jaeger.SpanRef, 0, len(data.Links))
for _, link := range data.Links {
refs = append(refs, &jaeger.SpanRef{
TraceIdHigh: bytesToInt64(link.TraceID[0:8]),
Expand Down
14 changes: 11 additions & 3 deletions jaeger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,13 @@ package jaeger

import (
"fmt"
"reflect"
"sort"
"testing"
"time"

"github.com/uber/jaeger-client-go/thrift-gen/jaeger"

"go.opencensus.io/trace"
"sort"
)

// TODO(jbd): Test export.
Expand Down Expand Up @@ -129,6 +128,7 @@ func Test_spanDataToThrift(t *testing.T) {
{Key: "message", VType: jaeger.TagType_STRING, VStr: &statusMessage},
}},
},
References: []*jaeger.SpanRef{},
},
},
}
Expand All @@ -141,7 +141,15 @@ func Test_spanDataToThrift(t *testing.T) {
sort.Slice(tt.want.Tags, func(i, j int) bool {
return tt.want.Tags[i].Key < tt.want.Tags[j].Key
})
if !reflect.DeepEqual(got, tt.want) {
gotBuf, err := serialize(got)
if err != nil {
t.Fatalf("failed to serialize: %v", err)
}
wantBuf, err := serialize(tt.want)
if err != nil {
t.Fatalf("failed to serialize: %v", err)
}
if gotBuf.String() != wantBuf.String() {
t.Errorf("spanDataToThrift()\nGot:\n%v\nWant;\n%v", got, tt.want)
}
})
Expand Down