diff --git a/Gopkg.lock b/Gopkg.lock index 36f61a0..9942ca0 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -37,6 +37,12 @@ packages = ["proto","ptypes","ptypes/any","ptypes/duration","ptypes/timestamp"] revision = "130e6b02ab059e7b717a096f397c5b60111cae74" +[[projects]] + branch = "master" + name = "github.com/grpc-ecosystem/grpc-opentracing" + packages = ["go/otgrpc"] + revision = "6c130eed1e297e1aa4d415a50c90d0c81c52677e" + [[projects]] name = "github.com/onsi/ginkgo" packages = [".","config","internal/codelocation","internal/containernode","internal/failer","internal/leafnodes","internal/remote","internal/spec","internal/spec_iterator","internal/specrunner","internal/suite","internal/testingtproxy","internal/writer","reporters","reporters/stenographer","reporters/stenographer/support/go-colorable","reporters/stenographer/support/go-isatty","types"] @@ -49,6 +55,12 @@ revision = "c893efa28eb45626cdaa76c9f653b62488858837" version = "v1.2.0" +[[projects]] + name = "github.com/opentracing/opentracing-go" + packages = [".","ext","log"] + revision = "1949ddbfd147afd4d964a9f00b24eb291e0e7c38" + version = "v1.0.2" + [[projects]] branch = "master" name = "golang.org/x/crypto" @@ -94,6 +106,6 @@ [solve-meta] analyzer-name = "dep" analyzer-version = 1 - inputs-digest = "64f25d2c53a571674c2c3a5e683f9a32c32219daa43826544fee2b9053b480be" + inputs-digest = "e6fcf0f570fa59937b27339b0071043dbd1b436235172a94e155b6285d926c24" solver-name = "gps-cdcl" solver-version = 1 diff --git a/dial.go b/dial.go index 00800a0..e7bbefc 100644 --- a/dial.go +++ b/dial.go @@ -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" ) @@ -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 @@ -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, diff --git a/server.go b/server.go index 88bf55b..d5ef8f6 100644 --- a/server.go +++ b/server.go @@ -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" @@ -67,6 +69,7 @@ type Options struct { SkipCompression bool SkipLoadReporting bool SkipInstrumentation bool + SkipTracing bool UnaryInterceptors []grpc.UnaryServerInterceptor StreamInterceptors []grpc.StreamServerInterceptor @@ -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))