I am playing around with the interceptor implementation (
https://github.com/grpc/grpc/issues/8767) and wanted to start exporting metrics such as per-request latency. To this end, is the servicer context the right place to keep track of such data? For example:
class MetricInterceptor(UnaryServerInterceptor, StreamServerInterceptor):
def intercept_unary(self, request, servicer_context, server_info, handler):
response = None
try:
servicer_context.start_time = time.time()
print('I was called')
response = handler(request)
except:
e = sys.exc_info()[0]
print(str(e))
raise
print('Request took {0} seconds'.format(time.time()-servicer_context.start_time))
return response
...
Thanks for any help.
Amit.