Tracing for gRPC Server (#619)

* Implements tracing in the native gRPC server

* Undo some unnecessary changes

* Properly revert trace/setup.go this time

* Some very very basic tests

* Remove warning for non-Trace middleware
This commit is contained in:
John Belamaric
2017-04-18 11:10:49 -04:00
committed by GitHub
parent 3b6eab2256
commit 5a60090933
6 changed files with 72 additions and 11 deletions

View File

@@ -6,7 +6,9 @@ import (
"fmt"
"net"
"github.com/grpc-ecosystem/grpc-opentracing/go/otgrpc"
"github.com/miekg/dns"
opentracing "github.com/opentracing/opentracing-go"
"golang.org/x/net/context"
"google.golang.org/grpc"
"google.golang.org/grpc/peer"
@@ -30,10 +32,6 @@ func NewServergRPC(addr string, group []*Config) (*servergRPC, error) {
return nil, err
}
gs := &servergRPC{Server: s}
gs.grpcServer = grpc.NewServer()
// trace foo... TODO(miek)
pb.RegisterDnsServiceServer(gs.grpcServer, gs)
return gs, nil
}
@@ -43,6 +41,18 @@ func (s *servergRPC) Serve(l net.Listener) error {
s.listenAddr = l.Addr()
s.m.Unlock()
if s.Tracer() != nil {
onlyIfParent := func(parentSpanCtx opentracing.SpanContext, method string, req, resp interface{}) bool {
return parentSpanCtx != nil
}
intercept := otgrpc.OpenTracingServerInterceptor(s.Tracer(), otgrpc.IncludingSpans(onlyIfParent))
s.grpcServer = grpc.NewServer(grpc.UnaryInterceptor(intercept))
} else {
s.grpcServer = grpc.NewServer()
}
pb.RegisterDnsServiceServer(s.grpcServer, s)
return s.grpcServer.Serve(l)
}