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.
The order of interceptors matters. Considering all server interceptors, the correct way of installation is:
WIP
When the LOG_LEVEL
env variable is set to INFO
then the server logs out.
When the LOG_LEVEL
env variable is set to DEBUG
then the server additionally adds the request to the log message. (Note, adding the response is currently blocked by this gRPC issue.)
GRPC::RpcServer.new(
interceptors: [
GrpcInterceptors::Server::StatsDMetrics.new
]
)
The server emits a histogram metric called grpc_latency_seconds
with the following tags:
grpc_method
representing the called methodgrpc_service
representing the servicegrpc_type
representing the gRPC kind of method
# 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
GRPC::RpcServer.new(
interceptors: [
GrpcInterceptors::Server::OpenTelemetryTracingInstrument.new
]
)
GRPC::RpcServer.new(
interceptors: [
GrpcInterceptors::Client::OpenTelemetryTracingInstrument.new
]
)
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
.
bundle exec rake build
bundle exec rake release