|
32 | 32 | from google.protobuf.json_format import MessageToJson |
33 | 33 | from grpc.experimental import aio # type: ignore |
34 | 34 |
|
35 | | -from google.cloud.spanner_v1.metrics.metrics_interceptor import MetricsInterceptor |
| 35 | +from google.cloud.spanner_v1.metrics.metrics_interceptor import ( |
| 36 | + AsyncMetricsInterceptor, |
| 37 | + MetricsInterceptor, |
| 38 | +) |
36 | 39 | from google.cloud.spanner_v1.types import ( |
37 | 40 | commit_response, |
38 | 41 | location, |
@@ -327,6 +330,26 @@ def __init__( |
327 | 330 | ], |
328 | 331 | ) |
329 | 332 |
|
| 333 | + if metrics_interceptor is not None: |
| 334 | + self._metrics_interceptor = AsyncMetricsInterceptor() |
| 335 | + # Attach interceptor directly since grpc.aio does not provide intercept_channel. |
| 336 | + if hasattr(self._grpc_channel, "_unary_unary_interceptors"): |
| 337 | + self._grpc_channel._unary_unary_interceptors.append( |
| 338 | + self._metrics_interceptor |
| 339 | + ) |
| 340 | + if hasattr(self._grpc_channel, "_unary_stream_interceptors"): |
| 341 | + self._grpc_channel._unary_stream_interceptors.append( |
| 342 | + self._metrics_interceptor |
| 343 | + ) |
| 344 | + if hasattr(self._grpc_channel, "_stream_unary_interceptors"): |
| 345 | + self._grpc_channel._stream_unary_interceptors.append( |
| 346 | + self._metrics_interceptor |
| 347 | + ) |
| 348 | + if hasattr(self._grpc_channel, "_stream_stream_interceptors"): |
| 349 | + self._grpc_channel._stream_stream_interceptors.append( |
| 350 | + self._metrics_interceptor |
| 351 | + ) |
| 352 | + |
330 | 353 | self._interceptor = _LoggingClientAIOInterceptor() |
331 | 354 | self._grpc_channel._unary_unary_interceptors.append(self._interceptor) |
332 | 355 | self._logged_channel = self._grpc_channel |
|
0 commit comments