Last active
July 17, 2019 03:51
-
-
Save masroorhasan/ee8ba4e4e7e3c4e83e4549ff977fc385 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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