Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gRPC instrumentor server does not work #879

Closed
cnnradams opened this issue Jul 3, 2020 · 1 comment
Closed

gRPC instrumentor server does not work #879

cnnradams opened this issue Jul 3, 2020 · 1 comment
Labels
bug Something isn't working

Comments

@cnnradams
Copy link
Member

cnnradams commented Jul 3, 2020

Describe your environment
python3.7, working out of #878

Steps to reproduce
I have a sample gRPC server/client in #878, so checkout that and then run the test

import grpc

from opentelemetry.ext.grpc import server_interceptor
from opentelemetry.ext.grpc.grpcext import intercept_server
from opentelemetry.test.test_base import TestBase

from ._client import simple_method, server_streaming_method, client_streaming_method, bidirectional_streaming_method
from ._server import create_test_server
from tests.protobuf import test_server_pb2_grpc

class TestServerProto(TestBase):
    def setUp(self):
        super().setUp()
        server = create_test_server(25565)

        interceptor = server_interceptor()
        self.server = intercept_server(server, interceptor)

        self.server.start()

        self.channel = grpc.insecure_channel("localhost:25565")
        self._stub = test_server_pb2_grpc.GRPCTestServerStub(self.channel)

    def tearDown(self):
        super().tearDown()
        self.server.stop(None)

    def test_unary_unary(self):
        simple_method(self._stub)

        spans = self.memory_exporter.get_finished_spans()
        self.assertEqual(len(spans), 1)
        span = spans[0]

It raises

______________________________________________________________________________ TestServerProto.test_unary_unary _______________________________________________________________________________

self = <tests.test_server_interceptor.TestServerProto testMethod=test_unary_unary>

    def test_unary_unary(self):
        simple_method(self._stub)
    
        spans = self.memory_exporter.get_finished_spans()
>       self.assertEqual(len(spans), 1)
E       AssertionError: 0 != 1

test_server_interceptor.py:32: AssertionError

What is the expected behavior?
There should be a span since I ran intercept_server, as shown in test_server_interceptor.py

Additional context
test_server_interceptor.py works, what is the difference between my code example and it (does my auto-generated pb2 not actually call channel.unary_unary)?

The actual example works properly (excluding server tracing of course), and can be instrumented by the client, see test_client_interceptor.py

also note that my PR did not change anything about the server interceptor, only the client

@cnnradams
Copy link
Member Author

cnnradams commented Jul 13, 2020

resolved: need to add interceptor before adding your servicer to server instead of after 😬

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant