From f9e83c6ea54df8d572c883b44b63a91ef8103b14 Mon Sep 17 00:00:00 2001 From: mmargulis Date: Fri, 18 Oct 2019 11:09:44 -0700 Subject: [PATCH 1/2] Added SpanKind for gRPC Server and Client --- contrib/google.golang.org/grpc/client.go | 9 +++++++++ contrib/google.golang.org/grpc/server.go | 13 +++++++++++++ 2 files changed, 22 insertions(+) diff --git a/contrib/google.golang.org/grpc/client.go b/contrib/google.golang.org/grpc/client.go index f1dcaf7f..eab051da 100644 --- a/contrib/google.golang.org/grpc/client.go +++ b/contrib/google.golang.org/grpc/client.go @@ -29,6 +29,9 @@ func (cs *clientStream) RecvMsg(m interface{}) (err error) { cs.cfg.clientServiceName(), cs.cfg.analyticsRate, ) + + span.SetTag(ext.SpanKind, ext.SpanKindClient) + if p, ok := peer.FromContext(cs.Context()); ok { setSpanTargetFromPeer(span, *p) } @@ -47,6 +50,9 @@ func (cs *clientStream) SendMsg(m interface{}) (err error) { cs.cfg.clientServiceName(), cs.cfg.analyticsRate, ) + + span.SetTag(ext.SpanKind, ext.SpanKindClient) + if p, ok := peer.FromContext(cs.Context()); ok { setSpanTargetFromPeer(span, *p) } @@ -142,6 +148,9 @@ func doClientRequest( cfg.clientServiceName(), cfg.analyticsRate, ) + + span.SetTag(ext.SpanKind, ext.SpanKindClient) + ctx = injectSpanIntoContext(ctx) // fill in the peer so we can add it to the tags diff --git a/contrib/google.golang.org/grpc/server.go b/contrib/google.golang.org/grpc/server.go index b30a5acb..2169c01a 100644 --- a/contrib/google.golang.org/grpc/server.go +++ b/contrib/google.golang.org/grpc/server.go @@ -4,6 +4,7 @@ import ( context "golang.org/x/net/context" "google.golang.org/grpc" "github.com/signalfx/signalfx-go-tracing/ddtrace" + "github.com/signalfx/signalfx-go-tracing/ddtrace/ext" ) type serverStream struct { @@ -34,6 +35,9 @@ func (ss *serverStream) RecvMsg(m interface{}) (err error) { ss.cfg.serverServiceName(), ss.cfg.analyticsRate, ) + + span.SetTag(ext.SpanKind, ext.SpanKindServer) + defer func() { finishWithError(span, err, ss.cfg) }() } err = ss.ServerStream.RecvMsg(m) @@ -49,6 +53,9 @@ func (ss *serverStream) SendMsg(m interface{}) (err error) { ss.cfg.serverServiceName(), ss.cfg.analyticsRate, ) + + span.SetTag(ext.SpanKind, ext.SpanKindServer) + defer func() { finishWithError(span, err, ss.cfg) }() } err = ss.ServerStream.SendMsg(m) @@ -78,6 +85,9 @@ func StreamServerInterceptor(opts ...Option) grpc.StreamServerInterceptor { cfg.serviceName, cfg.analyticsRate, ) + + span.SetTag(ext.SpanKind, ext.SpanKindServer) + defer func() { finishWithError(span, err, cfg) }() } @@ -109,6 +119,9 @@ func UnaryServerInterceptor(opts ...Option) grpc.UnaryServerInterceptor { cfg.serverServiceName(), cfg.analyticsRate, ) + + span.SetTag(ext.SpanKind, ext.SpanKindServer) + resp, err := handler(ctx, req) finishWithError(span, err, cfg) return resp, err From 9da866c6a008d244b91e5885b01356b4c7b90997 Mon Sep 17 00:00:00 2001 From: mobilus Date: Fri, 18 Oct 2019 16:49:24 -0700 Subject: [PATCH 2/2] Removed SpanKind in Stream Methods --- contrib/google.golang.org/grpc/client.go | 4 ---- contrib/google.golang.org/grpc/server.go | 4 ---- 2 files changed, 8 deletions(-) diff --git a/contrib/google.golang.org/grpc/client.go b/contrib/google.golang.org/grpc/client.go index eab051da..23fee075 100644 --- a/contrib/google.golang.org/grpc/client.go +++ b/contrib/google.golang.org/grpc/client.go @@ -30,8 +30,6 @@ func (cs *clientStream) RecvMsg(m interface{}) (err error) { cs.cfg.analyticsRate, ) - span.SetTag(ext.SpanKind, ext.SpanKindClient) - if p, ok := peer.FromContext(cs.Context()); ok { setSpanTargetFromPeer(span, *p) } @@ -51,8 +49,6 @@ func (cs *clientStream) SendMsg(m interface{}) (err error) { cs.cfg.analyticsRate, ) - span.SetTag(ext.SpanKind, ext.SpanKindClient) - if p, ok := peer.FromContext(cs.Context()); ok { setSpanTargetFromPeer(span, *p) } diff --git a/contrib/google.golang.org/grpc/server.go b/contrib/google.golang.org/grpc/server.go index 2169c01a..8b51775b 100644 --- a/contrib/google.golang.org/grpc/server.go +++ b/contrib/google.golang.org/grpc/server.go @@ -36,8 +36,6 @@ func (ss *serverStream) RecvMsg(m interface{}) (err error) { ss.cfg.analyticsRate, ) - span.SetTag(ext.SpanKind, ext.SpanKindServer) - defer func() { finishWithError(span, err, ss.cfg) }() } err = ss.ServerStream.RecvMsg(m) @@ -54,8 +52,6 @@ func (ss *serverStream) SendMsg(m interface{}) (err error) { ss.cfg.analyticsRate, ) - span.SetTag(ext.SpanKind, ext.SpanKindServer) - defer func() { finishWithError(span, err, ss.cfg) }() } err = ss.ServerStream.SendMsg(m)