grpc
grpc copied to clipboard
Provide a mechanism to capture exceptions during request handling
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.
@tony612 can you please at this PR? this is a heavily needed feature and will make debugging much simpler. thanks
It looks good overall. I just wonder if we can implement this feature with only interceptors?