Hey all,
I am writing a experimental logging server side interceptor (based of
https://github.com/grpc/grpc/pull/12778) which will log any unhandled
exceptions and set an appropriate code and details as follows:
def log_errors(func):
from functools import wraps
@wraps(func)
def wrapper(*args, **kw):
metadata = {}
metadata['timestamp'] =
datetime.datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%S.%fZ')
if isinstance(args[4], grpc._server._Context):
servicer_context = args[4]
metadata.update(dict(servicer_context.invocation_metadata()))
try:
result = func(*args, **kw)
except Exception as e:
logger.error(e, exc_info=True, extra=metadata)
servicer_context.set_details(str(e))
servicer_context.set_code(grpc.StatusCode.UNKNOWN)
# TODO: need to return an appropriate response type here
# Currently this will raise a serialization error on the server
# side
return None
else:
return result
return wrapper
The problem here is that i get a serialisation error since I return None if
there is an exception. As per
https://github.com/grpc/grpc/issues/4417#issuecomment-242998794, basically
I am likely seeing the manifestation of "Even after setting a non-OK status
code, service-side code must still return a value of the appropriate type
(perhaps we should soften this to "may", but there's one edge-case use case
that might get broken by that, so I'll have to think about it)."
Is there a way to achieve returning an empty response without serialisation
error? Thanks for any insights.
Best Wishes,
Amit.
--
You received this message because you are subscribed to the Google Groups
"grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/grpc-io.
To view this discussion on the web visit
https://groups.google.com/d/msgid/grpc-io/CANODV3kW_dE_GMzaQeRifkSa_az_C_uo%3DMULgviXN5tVb4ru9g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.