scalapb / zio-grpc

ScalaPB meets ZIO: write purely functional gRPC services and clients using ZIO
Apache License 2.0
259 stars 82 forks source link

Wrap an entire call/response chain in ZClientInterceptor #309

Open frekw opened 2 years ago

frekw commented 2 years ago

Hi!

I'm trying to write a (actually two) general ZClientInterceptor that adds metrics and tracing for any outgoing gRPC call for the zio-grpc client.

However, ZClientInterceptor today only allows me to modify the outgoing call, and I have no knowledge about when the call returns.

Ideally, I'd be able to register a wrapper that can follow the entire lifecycle of the call (ideally, in the tracing case, I'd also be able to control the execution in order to do something like Tracing.span(spanName)(outgoingCall) to ease integration with zio-telemetry).

sttp has some good examples of what such an interface can look like: https://sttp.softwaremill.com/en/latest/backends/wrappers/custom.html (wraps the entire execution) and https://sttp.softwaremill.com/en/latest/backends/wrappers/custom.html#listener-backend (reacts on events and allows one to propagate some state such as start time to measure execution duration).

joroKr21 commented 9 months ago

Another use case is to be able to set a deadline on the CallOptions based on the method descriptor. Currently that's not possible because the client call is already created so it's too late.