Skip to content

[gRPC] Does not work with stream-to-stream gRPC requests #1966

Closed
psydok/apm-agent-python
#1
@psydok

Description

@psydok

Describe the bug: I'm trying to add elastic apm for my gRPC service with unary-to-unary requests and stream-to-stream. Everything is fine with unary-to-unary requests. But stream-to-stream requests stop working.

The service stops accepting streaming requests altogether.

I think I saw somewhere that you wrote elastic does not support stream requests for gRPC. But I didn't think it would be a service-blocking problem.

Is there any way to get around it, to make custom processing for stream specifically?

To Reproduce

  1. Create a gRPC service with stream-to-stream and unary-to-unary endpoints.
class TestService(test_pb2_grpc.TestService):
    async def Streaming(self, request_iterator, context):
           count_of_request = 0
           async for request in request_iterator:
               count_of_request += 1
               yield test_pb2.Response(message=f"#{count_of_request } - ok")

    async def Unary(self, request, context):
           return test_pb2.Response(message="ok")
  1. Connect elastic apm.
elasticapm.instrument()

async def run_serve():
    apm_client = GRPCApmClient(
            {
                "SERVICE_NAME": "grpc-test",
                "SERVER_URL": "http://localhost:8200",
                "ENVIRONMENT": "test",
                "TRANSACTION_SAMPLE_RATE": 1.0,
                "SECRET_TOKEN": "qwerty",
            }
    )
    server = grpc.aio.server(
        futures.ThreadPoolExecutor(max_workers=10),
    )
    test_pb2_grpc.add_TestServicer_to_server(
        TestService(), server
    )
    server.add_insecure_port("[::]:50051")
    await server.start()
    await server.wait_for_termination()


if __name__ == "__main__":
    asyncio.run(run_serve())
  1. Make test requests
  2. Result: unary - works, stream - returns nothing, no logs in the service

Environment (please complete the following information)

  • OS: Linux
  • Python version: 3.10
  • Framework and version: gRPC 1.43.0
  • APM Server version: 6.20.0

Additional context

Add any other context about the problem here.

  • requirements.txt:

    Click to expand
    gcloud==0.18.3
    google-api-python-client==2.39.0
    grpcio-tools==1.43.0
    grpcio-health-checking==1.43.0
    setuptools==59.5.0
    elastic-apm
    sentry-sdk[grpcio]==1.31.0
    

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions