Skip to content

Commit

Permalink
Include tracing
Browse files Browse the repository at this point in the history
  • Loading branch information
dim committed Oct 5, 2017
1 parent 8b60cb7 commit e7d694a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
14 changes: 13 additions & 1 deletion Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions dial.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"time"

"github.com/bsm/grpclb"
"github.com/grpc-ecosystem/grpc-opentracing/go/otgrpc"
opentracing "github.com/opentracing/opentracing-go"
"golang.org/x/net/context"
"google.golang.org/grpc"
)
Expand All @@ -29,6 +31,8 @@ type DialOptions struct {
SkipInsecure bool
// SkipBlock makes Dial non-blocking (Dial won't wait for connection to be up before returning).
SkipBlock bool
// SkipTracing disables tracing.
SkipTracing bool

// LBAddr specifies github.com/bsm/grpclb balancer address, optional (no load-balancing unless provided).
LBAddr string
Expand All @@ -48,6 +52,11 @@ func (o *DialOptions) grpcDialOpts() (opts []grpc.DialOption) {
opts = append(opts, grpc.WithBlock())
}

if !o.SkipTracing {
tracer := opentracing.GlobalTracer()
opts = append(opts, grpc.WithUnaryInterceptor(otgrpc.OpenTracingClientInterceptor(tracer)))
}

if o.LBAddr != "" {
balancer := grpclb.PickFirst(&grpclb.Options{
Address: o.LBAddr,
Expand Down
8 changes: 8 additions & 0 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (

balancepb "github.com/bsm/grpclb/grpclb_backend_v1"
"github.com/bsm/grpclb/load"
"github.com/grpc-ecosystem/grpc-opentracing/go/otgrpc"
opentracing "github.com/opentracing/opentracing-go"
"google.golang.org/grpc"
"google.golang.org/grpc/health"
healthpb "google.golang.org/grpc/health/grpc_health_v1"
Expand Down Expand Up @@ -67,6 +69,7 @@ type Options struct {
SkipCompression bool
SkipLoadReporting bool
SkipInstrumentation bool
SkipTracing bool

UnaryInterceptors []grpc.UnaryServerInterceptor
StreamInterceptors []grpc.StreamServerInterceptor
Expand Down Expand Up @@ -94,6 +97,11 @@ func (o *Options) grpcServerOpts(lrm LoadReportMeter) []grpc.ServerOption {
schain = append(schain, DefaultInstrumenter.StreamServerInterceptor)
}

if !o.SkipTracing {
tracer := opentracing.GlobalTracer()
uchain = append(uchain, otgrpc.OpenTracingServerInterceptor(tracer))
}

if !o.SkipLoadReporting {
uchain = append(uchain, UnaryLoadReporter(lrm))
schain = append(schain, StreamLoadReporter(lrm))
Expand Down

0 comments on commit e7d694a

Please sign in to comment.