grpc-ecosystem / grpc-spring

Spring Boot starter module for gRPC framework.
https://grpc-ecosystem.github.io/grpc-spring/
Apache License 2.0
3.43k stars 809 forks source link

feat: Add gRPC server metrics #1031

Closed DNVindhya closed 5 months ago

DNVindhya commented 6 months ago

This PR adds server metrics defined in gRFC A66: OpenTelemetry Metrics to gRPC-Spring. Even though the gRFC mentions OpenTelmetry, to keep it in sync with existing metrics, this PR as well as future ones will use Micrometer for instrumentation.

Instrumentations to collect following server metrics are being introduced :

These metrics are not enabled yet. These can be enabled using GrpcServerConfigurer.

Related PR to add client metric #1021.

DNVindhya commented 5 months ago

The client implementation uses an interceptor to register this tracer. Does the server need that as well?

No, ServerStreamTracer.Factory cannot be added using ServerInterceptor. Unlike client, RPC flow for server is started at network i.e network -> stream tracer -> server interceptor. Instead GrpcServerConfigurer can be used to add ServerStreamTracer.Factory. For example,

public GrpcServerConfigurer streamTracerFactoryConfigurer(final MeterRegistry registry) {
        return builder -> builder.addStreamTracerFactory(
            new MetricsServerStreamTracers().getMetricsServerTracerFactory(registry));
    }