Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add: Grpc tracing for client and server #397

Merged
merged 11 commits into from Mar 13, 2020
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions go.mod
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Expand Up @@ -198,6 +198,8 @@ github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 h1:Ovs26xHkKqVztRpIrF/92Bcuy
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk=
github.com/grpc-ecosystem/grpc-gateway v1.9.5 h1:UImYN5qQ8tuGpGE16ZmjvcTtTw24zw1QAp/SlnNrZhI=
github.com/grpc-ecosystem/grpc-gateway v1.9.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
github.com/grpc-ecosystem/grpc-opentracing v0.0.0-20180507213350-8e809c8a8645 h1:MJG/KsmcqMwFAkh8mTnAwhyKoB+sTAnY4CACC110tbU=
github.com/grpc-ecosystem/grpc-opentracing v0.0.0-20180507213350-8e809c8a8645/go.mod h1:6iZfnjpejD4L/4DwD7NryNaJyCQdzwWwH2MWhCA90Kw=
github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed h1:5upAirOpQc1Q53c0bnx2ufif5kANL7bfZWcc6VJWJd8=
github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed/go.mod h1:tMWxXQ9wFIaZeTI9F+hmhFiGpFmhOHzyShyFUhRm0H4=
github.com/hashicorp/consul v1.5.3 h1:EmTWRf/cuqZk6Ug9tgFUVE9xNgJPpmBvJwJMvm+agSk=
Expand Down
11 changes: 10 additions & 1 deletion protocol/grpc/client.go
Expand Up @@ -21,6 +21,11 @@ import (
"reflect"
)

import (
"github.com/grpc-ecosystem/grpc-opentracing/go/otgrpc"
"github.com/opentracing/opentracing-go"
)

import (
zouyx marked this conversation as resolved.
Show resolved Hide resolved
"google.golang.org/grpc"
)
Expand All @@ -39,7 +44,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)
}
Expand Down
11 changes: 10 additions & 1 deletion protocol/grpc/server.go
Expand Up @@ -23,6 +23,11 @@ import (
"reflect"
)

import (
"github.com/grpc-ecosystem/grpc-opentracing/go/otgrpc"
"github.com/opentracing/opentracing-go"
)

import (
zouyx marked this conversation as resolved.
Show resolved Hide resolved
"google.golang.org/grpc"
)
Expand Down Expand Up @@ -63,7 +68,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)
Expand Down