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

Added SpanKind for gRPC Server and Client #25

Merged
2 commits merged into from
Oct 21, 2019
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
5 changes: 5 additions & 0 deletions contrib/google.golang.org/grpc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func (cs *clientStream) RecvMsg(m interface{}) (err error) {
cs.cfg.clientServiceName(),
cs.cfg.analyticsRate,
)

if p, ok := peer.FromContext(cs.Context()); ok {
setSpanTargetFromPeer(span, *p)
}
Expand All @@ -47,6 +48,7 @@ func (cs *clientStream) SendMsg(m interface{}) (err error) {
cs.cfg.clientServiceName(),
cs.cfg.analyticsRate,
)

if p, ok := peer.FromContext(cs.Context()); ok {
setSpanTargetFromPeer(span, *p)
}
Expand Down Expand Up @@ -142,6 +144,9 @@ func doClientRequest(
cfg.clientServiceName(),
cfg.analyticsRate,
)

span.SetTag(ext.SpanKind, ext.SpanKindClient)
siniy123 marked this conversation as resolved.
Show resolved Hide resolved

ctx = injectSpanIntoContext(ctx)

// fill in the peer so we can add it to the tags
Expand Down
9 changes: 9 additions & 0 deletions contrib/google.golang.org/grpc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -34,6 +35,7 @@ func (ss *serverStream) RecvMsg(m interface{}) (err error) {
ss.cfg.serverServiceName(),
ss.cfg.analyticsRate,
)

defer func() { finishWithError(span, err, ss.cfg) }()
}
err = ss.ServerStream.RecvMsg(m)
Expand All @@ -49,6 +51,7 @@ func (ss *serverStream) SendMsg(m interface{}) (err error) {
ss.cfg.serverServiceName(),
ss.cfg.analyticsRate,
)

defer func() { finishWithError(span, err, ss.cfg) }()
}
err = ss.ServerStream.SendMsg(m)
Expand Down Expand Up @@ -78,6 +81,9 @@ func StreamServerInterceptor(opts ...Option) grpc.StreamServerInterceptor {
cfg.serviceName,
cfg.analyticsRate,
)

span.SetTag(ext.SpanKind, ext.SpanKindServer)

defer func() { finishWithError(span, err, cfg) }()
}

Expand Down Expand Up @@ -109,6 +115,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
Expand Down