You've already forked opentelemetry-go
mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-11-23 22:34:47 +02:00
Send span.kind to jaeger and overwrite grpc metadata instead of using append (#441)
Co-authored-by: Rahul Patel <rghetia@yahoo.com>
This commit is contained in:
@@ -159,6 +159,7 @@ func spanDataToThrift(data *export.SpanData) *gen.Span {
|
|||||||
|
|
||||||
tags = append(tags, getInt64Tag("status.code", int64(data.Status)),
|
tags = append(tags, getInt64Tag("status.code", int64(data.Status)),
|
||||||
getStringTag("status.message", data.Status.String()),
|
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.
|
// Ensure that if Status.Code is not OK, that we set the "error" tag on the Jaeger span.
|
||||||
|
|||||||
@@ -158,6 +158,7 @@ func Test_spanDataToThrift(t *testing.T) {
|
|||||||
doubleValue := 123.456
|
doubleValue := 123.456
|
||||||
boolTrue := true
|
boolTrue := true
|
||||||
statusMessage := "Unknown"
|
statusMessage := "Unknown"
|
||||||
|
spanKind := "client"
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
@@ -191,7 +192,8 @@ func Test_spanDataToThrift(t *testing.T) {
|
|||||||
MessageEvents: []export.Event{
|
MessageEvents: []export.Event{
|
||||||
{Name: eventNameValue, Attributes: []core.KeyValue{key.String("k1", keyValue)}, Time: now},
|
{Name: eventNameValue, Attributes: []core.KeyValue{key.String("k1", keyValue)}, Time: now},
|
||||||
},
|
},
|
||||||
Status: codes.Unknown,
|
Status: codes.Unknown,
|
||||||
|
SpanKind: apitrace.SpanKindClient,
|
||||||
},
|
},
|
||||||
want: &gen.Span{
|
want: &gen.Span{
|
||||||
TraceIdLow: 651345242494996240,
|
TraceIdLow: 651345242494996240,
|
||||||
@@ -206,6 +208,7 @@ func Test_spanDataToThrift(t *testing.T) {
|
|||||||
{Key: "error", VType: gen.TagType_BOOL, VBool: &boolTrue},
|
{Key: "error", VType: gen.TagType_BOOL, VBool: &boolTrue},
|
||||||
{Key: "status.code", VType: gen.TagType_LONG, VLong: &statusCodeValue},
|
{Key: "status.code", VType: gen.TagType_LONG, VLong: &statusCodeValue},
|
||||||
{Key: "status.message", VType: gen.TagType_STRING, VStr: &statusMessage},
|
{Key: "status.message", VType: gen.TagType_STRING, VStr: &statusMessage},
|
||||||
|
{Key: "span.kind", VType: gen.TagType_STRING, VStr: &spanKind},
|
||||||
},
|
},
|
||||||
References: []*gen.SpanRef{
|
References: []*gen.SpanRef{
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ package grpctrace
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"google.golang.org/grpc/metadata"
|
"google.golang.org/grpc/metadata"
|
||||||
|
|
||||||
@@ -34,11 +33,14 @@ type metadataSupplier struct {
|
|||||||
|
|
||||||
func (s *metadataSupplier) Get(key string) string {
|
func (s *metadataSupplier) Get(key string) string {
|
||||||
values := s.metadata.Get(key)
|
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) {
|
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
|
// Inject injects correlation context and span context into the gRPC
|
||||||
|
|||||||
Reference in New Issue
Block a user