ruby-grpc-interceptors
A collection of Ruby interceptors (middlewares) for gRPC servers and clients.
Heavily inspired by grpc-ecosystem/go-grpc-middleware. The motivation is to have a unified behavior of gRPC services and integrated telemetry data (logging, tracing and metrics) regardless of the used language.
Contents
Server
The order of interceptors matters. Considering all server interceptors, the correct way of installation is:
</code>
Error handling
WIP
Logging
When the LOG_LEVEL env variable is set to INFO then the server logs out
StatsD metrics
GRPC::RpcServer.new(
interceptors: [
GrpcInterceptors::Server::StatsDMetrics.new
]
)
The server emits a histogram metric called grpc_latency_seconds with the following tags:
grpc_methodrepresenting the called methodgrpc_servicerepresenting the servicegrpc_typerepresenting the gRPC kind of method
[Experimental] A gauge metric of the server jobs queue
# https://github.com/grpc/grpc/blob/v1.62.0/src/ruby/lib/grpc/generic/rpc_server.rb#L43C9-L43C21
server.instance_variable_get(:@pool).jobs_waiting
OpenTelemetry tracing
GRPC::RpcServer.new(
interceptors: [
GrpcInterceptors::Server::OpenTelemetryTracingInstrument.new
]
)
Client
Logging
OpenTelemetry tracing
GRPC::RpcServer.new(
interceptors: [
GrpcInterceptors::Client::OpenTelemetryTracingInstrument.new
]
)
Development
Integration tests
Integration tests require some infrastructure to mimic gRPC client and server. For this purpose, there's a simple service definition in the test/integration/support/ping.proto. To re-generate *_pb.rb files run bundle exec rake proto:generate.
Releasing
bundle exec rake build
bundle exec rake release