コード例 #1
0
    def testGrpcPropagation(self):
        app = app_service.AppStub(self.grpcConn)
        app.CheckTraceHeader(app_messages.Empty())

        self._stopEnvironment()

        self.assertEqual(len(self.nginx_traces), 2)
コード例 #2
0
 def ListRecommendations(self, request, context):
     max_responses = 5
     response = catalog_stub.ListProducts(app_pb2.Empty())
     product_ids = [x.id for x in response.products]
     filtered_products = list(set(product_ids) - set(request.product_ids))
     num_products = len(filtered_products)
     num_return = min(max_responses, num_products)
     indices = random.sample(range(num_products), num_return)
     prod_list = [filtered_products[i] for i in indices]
     logger.info(
         '[Recv ListRecommendaitons] product_ids={}'.format(prod_list))
     resp = app_pb2.ListRecommendationsResponse()
     resp.product_ids.extend(prod_list)
     return resp
コード例 #3
0
 def CheckTraceHeader(self, request, context):
     metadata = dict(context.invocation_metadata())
     if 'x-ot-span-context' not in metadata:
         context.set_code(grpc.StatusCode.INTERNAL)
         context.set_details("Metadatum x-ot-span-context not found")
     return app_messages.Empty()