Skip to content

Commit b4e8599

Browse files
committed
add compat
1 parent 9868322 commit b4e8599

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

sentry_sdk/integrations/grpc/__init__.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from grpc.aio import Server as AsyncServer
77

88
from sentry_sdk.integrations import Integration
9+
from sentry_sdk.utils import parse_version
910

1011
from .client import ClientInterceptor
1112
from .server import ServerInterceptor
@@ -128,6 +129,17 @@ def patched_aio_server( # type: ignore
128129
) -> Server:
129130
server_interceptor = AsyncServerInterceptor()
130131
interceptors = [server_interceptor, *(interceptors or [])]
132+
133+
try:
134+
# We prefer interceptors as a list because of compatibility with
135+
# opentelemetry https://github.com/getsentry/sentry-python/issues/4389
136+
# However, prior to grpc 1.42.0, only tuples were accepted, so we
137+
# have no choice there.
138+
if parse_version(grpc.__version__) < (1, 42, 0):
139+
interceptors = tuple(interceptors)
140+
except Exception:
141+
pass
142+
131143
return func(*args, interceptors=interceptors, **kwargs) # type: ignore
132144

133145
return patched_aio_server # type: ignore

0 commit comments

Comments
 (0)