mirror of
https://github.com/coredns/coredns.git
synced 2025-11-10 22:12:21 -05:00
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:
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user