Skip to content

Commit

Permalink
Send span.kind to jaeger and overwrite grpc metadata instead of using…
Browse files Browse the repository at this point in the history
… append (#441)

Co-authored-by: Rahul Patel <[email protected]>
  • Loading branch information
amrmahdi and rghetia authored Jan 31, 2020
1 parent 405a92a commit 8fcdf8b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions exporter/trace/jaeger/jaeger.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ func spanDataToThrift(data *export.SpanData) *gen.Span {

tags = append(tags, getInt64Tag("status.code", int64(data.Status)),
getStringTag("status.message", data.Status.String()),
getStringTag("span.kind", data.SpanKind.String()),
)

// Ensure that if Status.Code is not OK, that we set the "error" tag on the Jaeger span.
Expand Down
5 changes: 4 additions & 1 deletion exporter/trace/jaeger/jaeger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ func Test_spanDataToThrift(t *testing.T) {
doubleValue := 123.456
boolTrue := true
statusMessage := "Unknown"
spanKind := "client"

tests := []struct {
name string
Expand Down Expand Up @@ -191,7 +192,8 @@ func Test_spanDataToThrift(t *testing.T) {
MessageEvents: []export.Event{
{Name: eventNameValue, Attributes: []core.KeyValue{key.String("k1", keyValue)}, Time: now},
},
Status: codes.Unknown,
Status: codes.Unknown,
SpanKind: apitrace.SpanKindClient,
},
want: &gen.Span{
TraceIdLow: 651345242494996240,
Expand All @@ -206,6 +208,7 @@ func Test_spanDataToThrift(t *testing.T) {
{Key: "error", VType: gen.TagType_BOOL, VBool: &boolTrue},
{Key: "status.code", VType: gen.TagType_LONG, VLong: &statusCodeValue},
{Key: "status.message", VType: gen.TagType_STRING, VStr: &statusMessage},
{Key: "span.kind", VType: gen.TagType_STRING, VStr: &spanKind},
},
References: []*gen.SpanRef{
{
Expand Down
8 changes: 5 additions & 3 deletions plugin/grpctrace/grpctrace.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package grpctrace

import (
"context"
"strings"

"google.golang.org/grpc/metadata"

Expand All @@ -34,11 +33,14 @@ type metadataSupplier struct {

func (s *metadataSupplier) Get(key string) string {
values := s.metadata.Get(key)
return strings.Join(values, ",")
if len(values) == 0 {
return ""
}
return values[0]
}

func (s *metadataSupplier) Set(key string, value string) {
s.metadata.Append(key, value)
s.metadata.Set(key, value)
}

// Inject injects correlation context and span context into the gRPC
Expand Down

0 comments on commit 8fcdf8b

Please sign in to comment.