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 instrument throw exception if a user set interceptor as tuple type. #2780

Open
daniel-lee-sb opened this issue Aug 6, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@daniel-lee-sb
Copy link

Describe your environment

OS: (e.g, Ubuntu)
Python version: (e.g., Python 3.8.10)
Package version: (e.g., 0.46.0)

What happened?

The following method expects an interceptor of the list type, but some libraries pass interceptors as tuples. (Example: https://pypi.org/project/py-grpc-prometheus/)

I think it would be better to check type of change type as list.

    def _instrument(self, **kwargs):
        self._original_func = grpc.server
        tracer_provider = kwargs.get("tracer_provider")

        def server(*args, **kwargs):
            if "interceptors" in kwargs:
                # add our interceptor as the first
                kwargs["interceptors"].insert(
                    0,
                    server_interceptor(
                        tracer_provider=tracer_provider, filter_=self._filter
                    ),
                )
            else:
                kwargs["interceptors"] = [
                    server_interceptor(
                        tracer_provider=tracer_provider, filter_=self._filter
                    )
                ]
            return self._original_func(*args, **kwargs)

        grpc.server = server

Steps to Reproduce

You can download https://pypi.org/project/py-grpc-prometheus/.
And setup like the following.

server = grpc.server(futures.ThreadPoolExecutor(max_workers=10),
interceptors=(PromServerInterceptor(),))

/site-packages/opentelemetry/instrumentation/grpc/__init__.py", line 338, in server
   kwargs["interceptors"].insert(
 AttributeError: 'tuple' object has no attribute 'insert'

Expected Result

Even though the user sends an interceptor as tuple, grpc instrument should work as expected.

Actual Result

throw error because tuple does not have insert attribute.

Additional context

No response

Would you like to implement a fix?

Yes

@daniel-lee-sb daniel-lee-sb added the bug Something isn't working label Aug 6, 2024
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