Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send span.kind to jaeger and overwrite grpc metadata instead of appending #441

Merged
merged 3 commits into from
Jan 31, 2020
Merged
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
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like this needs an explanation. There's no testing here, which suggests the correct behavior might not be well understood. Can you add some detail?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This follows the same behavior of the httptrace. What happens is if there is an existing traceparent metadata in the context (due to an incoming RPC to the server side) and on the server the RPC is forwarded (proxied), the traceparent header will be appended, causing it to be invalid. And hence when it is received on another server, the parsing of the traceparent header fails and assumes an empty context, since the traceparent value is a concatenated with a ,.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say it's a good change, but maybe we should add a text to the propagation.Supplier interface that it acts on single-valued keys, so implementations of the interface should avoid appending operations.

}

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