Skip to content

Commit

Permalink
grpc: Annotate requests with connection state
Browse files Browse the repository at this point in the history
  • Loading branch information
dfinkel committed Dec 9, 2019
1 parent eb21299 commit da6a423
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion grpc/grpcclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
gc "github.com/vimeo/galaxycache"
pb "github.com/vimeo/galaxycache/galaxycachepb"
"go.opencensus.io/plugin/ocgrpc"
"go.opencensus.io/trace"

"google.golang.org/grpc"
"google.golang.org/grpc/status"
Expand All @@ -45,7 +46,13 @@ type grpcFetcher struct {
// certificates on the peers operating as servers should specify
// grpc.WithInsecure() as one of the arguments.
func NewGRPCFetchProtocol(dialOpts ...grpc.DialOption) *GRPCFetchProtocol {
dialOpts = append(dialOpts, grpc.WithStatsHandler(&ocgrpc.ClientHandler{}))
dialOpts = append(dialOpts, grpc.WithStatsHandler(&ocgrpc.ClientHandler{
StartOptions: trace.StartOptions{
// Preserve the sampling-decision of the parent span
Sampler: nil,
SpanKind: trace.SpanKindClient,
},
}))
return &GRPCFetchProtocol{PeerDialOptions: dialOpts}
}

Expand All @@ -64,6 +71,8 @@ func (gp *GRPCFetchProtocol) NewFetcher(address string) (gc.RemoteFetcher, error
// Fetch here implements the RemoteFetcher interface for
// sending Gets to peers over an RPC connection
func (g *grpcFetcher) Fetch(ctx context.Context, galaxy string, key string) ([]byte, error) {
span := trace.FromContext(ctx)
span.Annotatef(nil, "fetching from %s; connection state %s", g.address, g.conn.GetState())
resp, err := g.client.GetFromPeer(ctx, &pb.GetRequest{
Galaxy: galaxy,
Key: key,
Expand Down

0 comments on commit da6a423

Please sign in to comment.