Documentation
¶
Overview ¶
Package ppgrpc instruments the grpc/grpc-go package (https://github.com/grpc/grpc-go).
This package instruments gRPC servers and clients. To instrument a gRPC server, use UnaryServerInterceptor and StreamServerInterceptor.
grpcServer := grpc.NewServer( grpc.UnaryInterceptor(ppgrpc.UnaryServerInterceptor()), grpc.StreamInterceptor(ppgrpc.StreamServerInterceptor()), )
ppgrpc's server interceptor adds the pinpoint.Tracer to the gRPC server handler's context. By using the pinpoint.FromContext function, this tracer can be obtained.
func (s *Server) UnaryCallUnaryReturn(ctx context.Context, msg *testapp.Greeting) (*testapp.Greeting, error) { tracer := pinpoint.FromContext(ctx) tracer.NewSpanEvent("gRPC Server Handler").EndSpanEvent() return "hi", nil }
To instrument a gRPC client, use UnaryClientInterceptor and StreamClientInterceptor.
conn, err := grpc.Dial( "localhost:8080", grpc.WithUnaryInterceptor(ppgrpc.UnaryClientInterceptor()), grpc.WithStreamInterceptor(ppgrpc.StreamClientInterceptor()), )
It is necessary to pass the context containing the pinpoint.Tracer to grpc.Client.
client := testapp.NewHelloClient(conn) client.UnaryCallUnaryReturn(pinpoint.NewContext(context.Background(), tracer), greeting)
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func StreamClientInterceptor ¶
func StreamClientInterceptor() grpc.StreamClientInterceptor
StreamClientInterceptor returns a new grpc.StreamClientInterceptor ready to instrument.
func StreamServerInterceptor ¶
func StreamServerInterceptor() grpc.StreamServerInterceptor
StreamServerInterceptor returns a grpc.StreamServerInterceptor ready to instrument and adds the pinpoint.Tracer to the grpc.StreamHandler's context. By using the pinpoint.FromContext function, this tracer can be obtained.
func UnaryClientInterceptor ¶
func UnaryClientInterceptor() grpc.UnaryClientInterceptor
UnaryClientInterceptor returns a new grpc.UnaryClientInterceptor ready to instrument.
func UnaryServerInterceptor ¶
func UnaryServerInterceptor() grpc.UnaryServerInterceptor
UnaryServerInterceptor returns a grpc.UnaryServerInterceptor ready to instrument and adds the pinpoint.Tracer to the grpc.UnaryHandler's context. By using the pinpoint.FromContext function, this tracer can be obtained.
Types ¶
This section is empty.