Skip to content

Instantly share code, notes, and snippets.

@masroorhasan
Last active July 17, 2019 03:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save masroorhasan/ee8ba4e4e7e3c4e83e4549ff977fc385 to your computer and use it in GitHub Desktop.
Save masroorhasan/ee8ba4e4e7e3c4e83e4549ff977fc385 to your computer and use it in GitHub Desktop.
package grpc_client
import (
"github.com/opentracing/opentracing-go"
"github.com/grpc-ecosystem/go-grpc-middleware/tracing/opentracing"
"github.com/grpc-ecosystem/go-grpc-middleware"
"google.golang.org/grpc"
"github.com/masroorhasan/myapp/tracer"
)
func NewClientConn(address string) (*grpc.ClientConn, error) {
// initialize tracer
tracer, closer, err := tracer.NewTracer()
defer closer.Close()
if err != nil {
return &grpc.ClientConn{}, err
}
// initialize client with tracing interceptor using grpc client side chaining
return grpc.Dial(
address,
grpc.WithStreamInterceptor(grpc_middleware.ChainStreamClient(
grpc_opentracing.StreamClientInterceptor(grpc_opentracing.WithTracer(tracer)),
)),
grpc.WithUnaryInterceptor(grpc_middleware.ChainUnaryClient(
grpc_opentracing.UnaryClientInterceptor(grpc_opentracing.WithTracer(tracer)),
)),
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment