modulepackage
0.12.0
Repository: https://github.com/mahboubii/grpcmetrics.git
Documentation: pkg.go.dev
# README
Go OpenTelemtry gRPC Metrics Instrumention
It is an OpenTelemetry (OTel) metric instrumentation for Golang gRPC servers and clients based on gRPC Stats.
Install
$ go get github.com/mahboubii/grpcmetrics
Usage
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.
Server side metrics
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())),
)),
)
Client side metrics
handler, err := grpcmetrics.NewClientHandler()
if err != nil {
log.Panic(err)
}
connection, err := grpc.Dial("server:8080", grpc.WithStatsHandler(handler))
# Packages
No description provided by the author
# Functions
No description provided by the author
No description provided by the author
WithInstrumentationName returns an Option to set custom name for metrics scope.
WithInstrumentLatency enable instrument for rpc.{server|client}.duration.
WithInstrumentSizes enable instrument for rpc.{server|client}.response.size and rpc.{server|client}.request.size.
WithMeterProvider returns an Option to use custom MetricProvider when creating metrics.
# Constants
DefaultInstrumentationName is the default used when creating meters.
# Interfaces
Option applies an option value when creating a Handler.