Documentation ¶
Overview ¶
Package statshandler implements a grpc.StatsHandler that records OpenTelemetry traces and metrics
Index ¶
- Constants
- type ClientHandler
- func (c *ClientHandler) HandleConn(_ context.Context, _ stats.ConnStats)
- func (c *ClientHandler) HandleRPC(ctx context.Context, rs stats.RPCStats)
- func (c *ClientHandler) TagConn(ctx context.Context, _ *stats.ConnTagInfo) context.Context
- func (c *ClientHandler) TagRPC(ctx context.Context, info *stats.RPCTagInfo) context.Context
- type Option
- type ServerHandler
- func (s *ServerHandler) HandleConn(_ context.Context, _ stats.ConnStats)
- func (s *ServerHandler) HandleRPC(ctx context.Context, rs stats.RPCStats)
- func (s *ServerHandler) TagConn(ctx context.Context, _ *stats.ConnTagInfo) context.Context
- func (s *ServerHandler) TagRPC(ctx context.Context, info *stats.RPCTagInfo) context.Context
Examples ¶
Constants ¶
const (
// DefaultInstrumentationName is the default used when creating meters and tracers.
DefaultInstrumentationName = "otel-grpc-statshandler"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ClientHandler ¶
type ClientHandler struct {
// contains filtered or unexported fields
}
ServerHandler implements https://pkg.go.dev/google.golang.org/grpc/stats#ServerHandler It records OpenTelemetry metrics and traces.
Example ¶
package main import ( "google.golang.org/grpc" pb "google.golang.org/grpc/examples/helloworld/helloworld" statshandler "github.com/bakins/otel-grpc-statshandler" ) func main() { handler, err := statshandler.NewClientHandler() if err != nil { // handle error } conn, err := grpc.Dial("myaddress:port", grpc.WithStatsHandler(handler)) if err != nil { // handle error } client := pb.NewGreeterClient(conn) _ = client // use client }
Output:
func NewClientHandler ¶
func NewClientHandler(options ...Option) (*ClientHandler, error)
func (*ClientHandler) HandleConn ¶
func (c *ClientHandler) HandleConn(_ context.Context, _ stats.ConnStats)
HandleConn exists to satisfy gRPC stats.Handler.
func (*ClientHandler) HandleRPC ¶
func (c *ClientHandler) HandleRPC(ctx context.Context, rs stats.RPCStats)
HandleRPC implements per-RPC tracing and stats instrumentation.
func (*ClientHandler) TagConn ¶
func (c *ClientHandler) TagConn(ctx context.Context, _ *stats.ConnTagInfo) context.Context
TagConn exists to satisfy gRPC stats.Handler.
func (*ClientHandler) TagRPC ¶
func (c *ClientHandler) TagRPC(ctx context.Context, info *stats.RPCTagInfo) context.Context
TagRPC implements per-RPC context management.
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
Option applies an option value when creating a Handler
func WithInstrumentationName ¶
WithInstrumentationName returns an Option to use the TracerProvider when creating a Tracer.
func WithMeterProvider ¶
func WithMeterProvider(p metric.MeterProvider) Option
WithMeterProvider returns an Option to use the MetricProvider when creating metrics.
func WithPropagators ¶
func WithPropagators(p propagation.TextMapPropagator) Option
WithPropagator returns an Option to use the Propagator when extracting and injecting trace context from requests.
func WithTracerProvider ¶
func WithTracerProvider(p trace.TracerProvider) Option
WithTracerProvider returns an Option to use the TracerProvider when creating a Tracer.
type ServerHandler ¶
type ServerHandler struct {
// contains filtered or unexported fields
}
ServerHandler implements https://pkg.go.dev/google.golang.org/grpc/stats#ServerHandler It records OpenTelemetry metrics and traces.
Example ¶
package main import ( "google.golang.org/grpc" statshandler "github.com/bakins/otel-grpc-statshandler" ) func main() { handler, err := statshandler.NewServerHandler() if err != nil { // handle error } server := grpc.NewServer(grpc.StatsHandler(handler)) _ = server // use server }
Output:
func NewServerHandler ¶
func NewServerHandler(options ...Option) (*ServerHandler, error)
func (*ServerHandler) HandleConn ¶
func (s *ServerHandler) HandleConn(_ context.Context, _ stats.ConnStats)
HandleConn exists to satisfy gRPC stats.Handler.
func (*ServerHandler) HandleRPC ¶
func (s *ServerHandler) HandleRPC(ctx context.Context, rs stats.RPCStats)
HandleRPC implements per-RPC tracing and stats instrumentation.
func (*ServerHandler) TagConn ¶
func (s *ServerHandler) TagConn(ctx context.Context, _ *stats.ConnTagInfo) context.Context
TagConn exists to satisfy gRPC stats.Handler.
func (*ServerHandler) TagRPC ¶
func (s *ServerHandler) TagRPC(ctx context.Context, info *stats.RPCTagInfo) context.Context
TagRPC implements per-RPC context management.