|
6 | 6 | from grpc.aio import Server as AsyncServer
|
7 | 7 |
|
8 | 8 | from sentry_sdk.integrations import Integration
|
| 9 | +from sentry_sdk.utils import parse_version |
9 | 10 |
|
10 | 11 | from .client import ClientInterceptor
|
11 | 12 | from .server import ServerInterceptor
|
@@ -41,6 +42,8 @@ def __getitem__(self, _):
|
41 | 42 |
|
42 | 43 | P = ParamSpec("P")
|
43 | 44 |
|
| 45 | +GRPC_VERSION = parse_version(grpc.__version__) |
| 46 | + |
44 | 47 |
|
45 | 48 | def _wrap_channel_sync(func: Callable[P, Channel]) -> Callable[P, Channel]:
|
46 | 49 | "Wrapper for synchronous secure and insecure channel."
|
@@ -127,7 +130,21 @@ def patched_aio_server( # type: ignore
|
127 | 130 | **kwargs: P.kwargs,
|
128 | 131 | ) -> Server:
|
129 | 132 | server_interceptor = AsyncServerInterceptor()
|
130 |
| - interceptors = (server_interceptor, *(interceptors or [])) |
| 133 | + interceptors = [ |
| 134 | + server_interceptor, |
| 135 | + *(interceptors or []), |
| 136 | + ] # type: Sequence[grpc.ServerInterceptor] |
| 137 | + |
| 138 | + try: |
| 139 | + # We prefer interceptors as a list because of compatibility with |
| 140 | + # opentelemetry https://github.com/getsentry/sentry-python/issues/4389 |
| 141 | + # However, prior to grpc 1.42.0, only tuples were accepted, so we |
| 142 | + # have no choice there. |
| 143 | + if GRPC_VERSION is not None and GRPC_VERSION < (1, 42, 0): |
| 144 | + interceptors = tuple(interceptors) |
| 145 | + except Exception: |
| 146 | + pass |
| 147 | + |
131 | 148 | return func(*args, interceptors=interceptors, **kwargs) # type: ignore
|
132 | 149 |
|
133 | 150 | return patched_aio_server # type: ignore
|
|
0 commit comments