Documentation ¶
Overview ¶
Package ppkratos instruments the go-kratos/kratos/v2 package (https://github.com/go-kratos/kratos).
This package instruments kratos servers and clients. To instrument a kratos server, use ServerMiddleware.
httpSrv := http.NewServer( http.Address(":8000"), http.Middleware(ppkratos.ServerMiddleware()), )
The server middleware adds the pinpoint.Tracer to the kratos server handler's context. By using the pinpoint.FromContext function, this tracer can be obtained.
func (s *server) SayHello(ctx context.Context, in *helloworld.HelloRequest) (*helloworld.HelloReply, error) { tracer := pinpoint.FromContext(ctx) defer tracer.NewSpanEvent("f1").EndSpanEvent() ... }
To instrument a kratos client, use ClientMiddleware.
conn, err := transhttp.NewClient( context.Background(), transhttp.WithMiddleware(ppkratos.ClientMiddleware()), transhttp.WithEndpoint("127.0.0.1:8000"), )
It is necessary to pass the context containing the pinpoint.Tracer to kratos client.
client := pb.NewGreeterHTTPClient(conn) reply, err := client.SayHello(pinpoint.NewContext(context.Background(), tracer), &pb.HelloRequest{Name: "kratos"})
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ClientMiddleware ¶
func ClientMiddleware() middleware.Middleware
ClientMiddleware returns a client side middleware ready to instrument.
func ServerMiddleware ¶
func ServerMiddleware() middleware.Middleware
ServerMiddleware returns a server side middleware ready to instrument and adds the pinpoint.Tracer to the handler's context. By using the pinpoint.FromContext function, this tracer can be obtained.
Types ¶
This section is empty.