From 28234bcc3c963787a4678721c941de1fb8cbd58c Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Sun, 10 Nov 2024 20:16:08 +0300 Subject: [PATCH] add server type in metrics and tracing Signed-off-by: Vasiliy Tolstov --- grpc.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/grpc.go b/grpc.go index 577213a..38a9578 100644 --- a/grpc.go +++ b/grpc.go @@ -230,6 +230,7 @@ func (g *Server) handler(srv interface{}, stream grpc.ServerStream) error { tracer.WithSpanKind(tracer.SpanKindServer), tracer.WithSpanLabels( "endpoint", endpointName, + "server", "grpc", ), ) defer func() { @@ -291,18 +292,18 @@ func (g *Server) handler(srv interface{}, stream grpc.ServerStream) error { stream = &streamWrapper{ctx, stream} if !slices.Contains(meter.DefaultSkipEndpoints, endpointName) { - g.opts.Meter.Counter(semconv.ServerRequestInflight, "endpoint", endpointName).Inc() + g.opts.Meter.Counter(semconv.ServerRequestInflight, "endpoint", endpointName, "server", "grpc").Inc() defer func() { te := time.Since(ts) - g.opts.Meter.Summary(semconv.ServerRequestLatencyMicroseconds, "endpoint", endpointName).Update(te.Seconds()) - g.opts.Meter.Histogram(semconv.ServerRequestDurationSeconds, "endpoint", endpointName).Update(te.Seconds()) - g.opts.Meter.Counter(semconv.ServerRequestInflight, "endpoint", endpointName).Dec() + g.opts.Meter.Summary(semconv.ServerRequestLatencyMicroseconds, "endpoint", endpointName, "server", "grpc").Update(te.Seconds()) + g.opts.Meter.Histogram(semconv.ServerRequestDurationSeconds, "endpoint", endpointName, "server", "grpc").Update(te.Seconds()) + g.opts.Meter.Counter(semconv.ServerRequestInflight, "endpoint", endpointName, "server", "grpc").Dec() st := status.Convert(err) if st == nil || st.Code() == codes.OK { - g.opts.Meter.Counter(semconv.ServerRequestTotal, "endpoint", endpointName, "status", "success", "code", strconv.Itoa(int(codes.OK))).Inc() + g.opts.Meter.Counter(semconv.ServerRequestTotal, "endpoint", endpointName, "server", "grpc", "status", "success", "code", strconv.Itoa(int(codes.OK))).Inc() } else { - g.opts.Meter.Counter(semconv.ServerRequestTotal, "endpoint", endpointName, "status", "failure", "code", strconv.Itoa(int(st.Code()))).Inc() + g.opts.Meter.Counter(semconv.ServerRequestTotal, "endpoint", endpointName, "server", "grpc", "status", "failure", "code", strconv.Itoa(int(st.Code()))).Inc() } }() }