grpc icon indicating copy to clipboard operation
grpc copied to clipboard

Provide a mechanism to capture exceptions during request handling

Open freshtonic opened this issue 4 years ago • 1 comments

Interceptors are insufficient for capturing errors in the general case because they execute after a request has already been successfully decoded.

This commit introduces a new concept called an ExceptionSink. It is a behavior that exposes an error/2 function.

ExceptionSinks are attached to an Endpoint like this:

defmodule EndpointWithExceptionSink do
  use GRPC.Endpoint

  exception_sink ExceptionSink1
  exception_sink ExceptionSink2, foo: 1

  run Server
end

An ExceptionSink receives the raised exception and a stack trace, allowing the developer to process/forward that information to the observability tool of their choice.

Exceptions that are caught before sending to the exception sinks are reraised so that the existing behaviour is preserved.

freshtonic avatar Jun 18 '21 05:06 freshtonic

@tony612 can you please at this PR? this is a heavily needed feature and will make debugging much simpler. thanks

lessless avatar Nov 06 '21 11:11 lessless

It looks good overall. I just wonder if we can implement this feature with only interceptors?

tony612 avatar Feb 06 '23 05:02 tony612