|
1 | 1 | from functools import wraps |
2 | 2 |
|
3 | | -import grpc |
4 | | -from grpc import Channel, Server, intercept_channel |
5 | | -from grpc.aio import Channel as AsyncChannel |
6 | | -from grpc.aio import Server as AsyncServer |
7 | | - |
8 | 3 | from sentry_sdk.integrations import Integration |
9 | 4 | from sentry_sdk.utils import parse_version |
| 5 | +from sentry_sdk.integrations import DidNotEnable |
10 | 6 |
|
11 | 7 | from .client import ClientInterceptor |
12 | 8 | from .server import ServerInterceptor |
13 | | -from .aio.server import ServerInterceptor as AsyncServerInterceptor |
14 | | -from .aio.client import ( |
15 | | - SentryUnaryUnaryClientInterceptor as AsyncUnaryUnaryClientInterceptor, |
16 | | -) |
17 | | -from .aio.client import ( |
18 | | - SentryUnaryStreamClientInterceptor as AsyncUnaryStreamClientIntercetor, |
19 | | -) |
20 | 9 |
|
21 | 10 | from typing import TYPE_CHECKING, Any, Optional, Sequence |
22 | 11 |
|
| 12 | +try: |
| 13 | + import grpc |
| 14 | + from grpc import Channel, Server, intercept_channel |
| 15 | + from grpc.aio import Channel as AsyncChannel |
| 16 | + from grpc.aio import Server as AsyncServer |
| 17 | + |
| 18 | + from .aio.server import ServerInterceptor as AsyncServerInterceptor |
| 19 | + from .aio.client import ( |
| 20 | + SentryUnaryUnaryClientInterceptor as AsyncUnaryUnaryClientInterceptor, |
| 21 | + ) |
| 22 | + from .aio.client import ( |
| 23 | + SentryUnaryStreamClientInterceptor as AsyncUnaryStreamClientIntercetor, |
| 24 | + ) |
| 25 | +except ImportError: |
| 26 | + raise DidNotEnable("grpcio is not installed.") |
| 27 | + |
23 | 28 | # Hack to get new Python features working in older versions |
24 | 29 | # without introducing a hard dependency on `typing_extensions` |
25 | 30 | # from: https://stackoverflow.com/a/71944042/300572 |
|
0 commit comments