Skip to content
Snippets Groups Projects
Commit 5ea3f25f authored by fangyincheng's avatar fangyincheng Committed by GitHub
Browse files

Merge pull request #397 from zouyx/feature/grpctracing

Add: Grpc tracing for client and server
parents dc53cee1 1f379da2
No related branches found
No related tags found
No related merge requests found
......@@ -24,6 +24,7 @@ require (
github.com/grpc-ecosystem/go-grpc-middleware v1.0.0 // indirect
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect
github.com/grpc-ecosystem/grpc-gateway v1.9.5 // indirect
github.com/grpc-ecosystem/grpc-opentracing v0.0.0-20180507213350-8e809c8a8645
github.com/hashicorp/consul v1.5.3
github.com/hashicorp/consul/api v1.1.0
github.com/jehiah/go-strftime v0.0.0-20171201141054-1d33003b3869 // indirect
......
......@@ -22,6 +22,8 @@ import (
)
import (
"github.com/grpc-ecosystem/grpc-opentracing/go/otgrpc"
"github.com/opentracing/opentracing-go"
"google.golang.org/grpc"
)
......@@ -39,7 +41,11 @@ type Client struct {
// NewClient ...
func NewClient(url common.URL) *Client {
conn, err := grpc.Dial(url.Location, grpc.WithInsecure(), grpc.WithBlock())
// if global trace instance was set , it means trace function enabled. If not , will return Nooptracer
tracer := opentracing.GlobalTracer()
conn, err := grpc.Dial(url.Location, grpc.WithInsecure(), grpc.WithBlock(),
grpc.WithUnaryInterceptor(
otgrpc.OpenTracingClientInterceptor(tracer, otgrpc.LogPayloads())))
if err != nil {
panic(err)
}
......
......@@ -24,6 +24,8 @@ import (
)
import (
"github.com/grpc-ecosystem/grpc-opentracing/go/otgrpc"
"github.com/opentracing/opentracing-go"
"google.golang.org/grpc"
)
......@@ -63,7 +65,11 @@ func (s *Server) Start(url common.URL) {
if err != nil {
panic(err)
}
server := grpc.NewServer()
// if global trace instance was set , then server tracer instance can be get. If not , will return Nooptracer
tracer := opentracing.GlobalTracer()
server := grpc.NewServer(
grpc.UnaryInterceptor(otgrpc.OpenTracingServerInterceptor(tracer)))
key := url.GetParam(constant.BEAN_NAME_KEY, "")
service := config.GetProviderService(key)
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment