Documentation ¶
Overview ¶
Package grpctrace is a package to assist with tracing incoming and outgoing gRPC requests.
Index ¶
- type ClientStatsHandler
- func (c *ClientStatsHandler) HandleConn(ctx context.Context, cs stats.ConnStats)
- func (c *ClientStatsHandler) HandleRPC(ctx context.Context, rs stats.RPCStats)
- func (c *ClientStatsHandler) TagConn(ctx context.Context, cti *stats.ConnTagInfo) context.Context
- func (c *ClientStatsHandler) TagRPC(ctx context.Context, rti *stats.RPCTagInfo) context.Context
- type ServerStatsHandler
- func (s *ServerStatsHandler) HandleConn(ctx context.Context, cs stats.ConnStats)
- func (s *ServerStatsHandler) HandleRPC(ctx context.Context, rs stats.RPCStats)
- func (s *ServerStatsHandler) TagConn(ctx context.Context, cti *stats.ConnTagInfo) context.Context
- func (s *ServerStatsHandler) TagRPC(ctx context.Context, rti *stats.RPCTagInfo) context.Context
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ClientStatsHandler ¶
type ClientStatsHandler struct{}
ClientStatsHandler is a an implementation of grpc.StatsHandler that can be passed to grpc.Dial using grpc.WithStatsHandler to enable trace context propagation and automatic span creation for outgoing gRPC requests.
func NewClientStatsHandler ¶
func NewClientStatsHandler() *ClientStatsHandler
NewClientStatsHandler returns a StatsHandler that can be passed to grpc.Dial using grpc.WithStatsHandler to enable trace context propagation and automatic span creation for outgoing gRPC requests.
Example ¶
package main import ( "log" "go.opencensus.io/plugin/grpc/grpctrace" "google.golang.org/grpc" ) func main() { // Set up a new client connection with the OpenCensus // stats handler to enable tracing for the outgoing requests. conn, err := grpc.Dial("address", grpc.WithStatsHandler(grpctrace.NewClientStatsHandler())) if err != nil { log.Fatalf("did not connect: %v", err) } defer conn.Close() }
Output:
func (*ClientStatsHandler) HandleConn ¶
func (c *ClientStatsHandler) HandleConn(ctx context.Context, cs stats.ConnStats)
HandleConn is a no-op for this StatsHandler.
func (*ClientStatsHandler) HandleRPC ¶
func (c *ClientStatsHandler) HandleRPC(ctx context.Context, rs stats.RPCStats)
HandleRPC processes the RPC stats, adding information to the current trace span.
func (*ClientStatsHandler) TagConn ¶
func (c *ClientStatsHandler) TagConn(ctx context.Context, cti *stats.ConnTagInfo) context.Context
TagConn is a no-op for this StatsHandler.
func (*ClientStatsHandler) TagRPC ¶
func (c *ClientStatsHandler) TagRPC(ctx context.Context, rti *stats.RPCTagInfo) context.Context
TagRPC creates a new trace span for the client side of the RPC.
It returns ctx with the new trace span added and a serialization of the SpanContext added to the outgoing gRPC metadata.
type ServerStatsHandler ¶
type ServerStatsHandler struct{}
ServerStatsHandler is a an implementation of grpc.StatsHandler that can be passed to grpc.NewServer using grpc.StatsHandler to enable trace context propagation and automatic span creation for incoming gRPC requests..
func NewServerStatsHandler ¶
func NewServerStatsHandler() *ServerStatsHandler
NewServerStatsHandler returns a StatsHandler that can be passed to grpc.NewServer using grpc.StatsHandler to enable trace context propagation and automatic span creation for incoming gRPC requests.
Example ¶
package main import ( "go.opencensus.io/plugin/grpc/grpctrace" "google.golang.org/grpc" ) func main() { // Set up a new client connection with the OpenCensus // stats handler to enable tracing for the incoming requests. s := grpc.NewServer(grpc.StatsHandler(grpctrace.NewServerStatsHandler())) _ = s // use s }
Output:
func (*ServerStatsHandler) HandleConn ¶
func (s *ServerStatsHandler) HandleConn(ctx context.Context, cs stats.ConnStats)
HandleConn is a no-op for this StatsHandler.
func (*ServerStatsHandler) HandleRPC ¶
func (s *ServerStatsHandler) HandleRPC(ctx context.Context, rs stats.RPCStats)
HandleRPC processes the RPC stats, adding information to the current trace span.
func (*ServerStatsHandler) TagConn ¶
func (s *ServerStatsHandler) TagConn(ctx context.Context, cti *stats.ConnTagInfo) context.Context
TagConn is a no-op for this StatsHandler.
func (*ServerStatsHandler) TagRPC ¶
func (s *ServerStatsHandler) TagRPC(ctx context.Context, rti *stats.RPCTagInfo) context.Context
TagRPC creates a new trace span for the server side of the RPC.
It checks the incoming gRPC metadata in ctx for a SpanContext, and if it finds one, uses that SpanContext as the parent context of the new span.
It returns ctx, with the new trace span added.