It is an OpenTelemetry (OTel) metric instrumentation for Golang gRPC servers and clients based on gRPC Stats.
$ go get github.com/mahboubii/grpcmetrics
Metrics are reported based on General RFC conventions specefications with some exceptions for following metrics where a normal counter is used instead of histograms to reduce the metrics cardinality:
rpc.server.requests_per_rpc
rpc.server.responses_per_rpc
rpc.client.requests_per_rpc
rpc.client.responses_per_rpc
Keep in mind durations
, request.size
and response.size
are not reported by default. If you need to enable them check out the options.
handler, err := grpcmetrics.NewServerHandler()
if err != nil {
log.Panic(err)
}
server := grpc.NewServer(
grpc.StatsHandler(handler),
// disable default otelgrpc duration metric to avoid sending metrics twice:
grpc.UnaryInterceptor(grpc_middleware.ChainUnaryServer(
otelgrpc.UnaryServerInterceptor(otelgrpc.WithMeterProvider(otelmetric.NewNoopMeterProvider())),
)),
grpc.StreamInterceptor(grpc_middleware.ChainStreamServer(
otelgrpc.StreamServerInterceptor(otelgrpc.WithMeterProvider(otelmetric.NewNoopMeterProvider())),
)),
)
handler, err := grpcmetrics.NewClientHandler()
if err != nil {
log.Panic(err)
}
connection, err := grpc.Dial("server:8080", grpc.WithStatsHandler(handler))