def intercept_unary_unary(self, continuation, client_call_details,
                              request):
        """Intercepts and logs API interactions.

    Overrides abstract method defined in grpc.UnaryUnaryClientInterceptor.
    Args:
        continuation: a function to continue the request process.
        client_call_details: a grpc._interceptor._ClientCallDetails
            instance containing request metadata.
        request: the request value for the RPC.
    Returns:
        A grpc.Call/grpc.Future instance representing a service response.
    """
        start_time = time.time()
        response = continuation(client_call_details, request)
        time_taken = time.time() - start_time
        metrics.RPCDuration(time_taken)

        return response
示例#2
0
 def _ReportDuration(response, data):
     """Records the duration of a request."""
     del response  # Unused.
     duration = time.time() - data['start_time']
     metrics.RPCDuration(duration)
示例#3
0
 def _ReportDuration(unused_response, start_time):
     """Response handler."""
     duration = time.time() - start_time
     metrics.RPCDuration(duration)