Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ replacements:
- paths: [packages/google-cloud-spanner/google/cloud/spanner_v1/services/spanner/transports/grpc_asyncio.py]
before: '(from grpc\.experimental import aio # type: ignore\n\n)(?!from google\.cloud\.spanner_v1\.metrics)'
after: |
\g<1>from google.cloud.spanner_v1.metrics.metrics_interceptor import MetricsInterceptor
\g<1>from google.cloud.spanner_v1.metrics.metrics_interceptor import (
AsyncMetricsInterceptor,
MetricsInterceptor,
)
count: 1

- paths: [packages/google-cloud-spanner/google/cloud/spanner_v1/services/spanner/transports/grpc.py]
Expand Down Expand Up @@ -156,6 +159,32 @@ replacements:

\g<3>\g<4>
count: 1
- paths:
- packages/google-cloud-spanner/google/cloud/spanner_v1/services/spanner/transports/grpc_asyncio.py
before: '([ \t]+)(\("grpc\.keepalive_time_ms", 120000\),\n[ \t]+\](?:,\n[ \t]*|\n[ \t]*)\)\n+)([ \t]+)(self\._interceptor = _LoggingClientAIOInterceptor\(\)\n)'
after: |
\g<1>\g<2>\g<3>if metrics_interceptor is not None:
self._metrics_interceptor = AsyncMetricsInterceptor()
# Attach interceptor directly since grpc.aio does not provide intercept_channel.
if hasattr(self._grpc_channel, "_unary_unary_interceptors"):
self._grpc_channel._unary_unary_interceptors.append(
self._metrics_interceptor
)
if hasattr(self._grpc_channel, "_unary_stream_interceptors"):
self._grpc_channel._unary_stream_interceptors.append(
self._metrics_interceptor
)
if hasattr(self._grpc_channel, "_stream_unary_interceptors"):
self._grpc_channel._stream_unary_interceptors.append(
self._metrics_interceptor
)
if hasattr(self._grpc_channel, "_stream_stream_interceptors"):
self._grpc_channel._stream_stream_interceptors.append(
self._metrics_interceptor
)
Comment on lines +169 to +184

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

The asynchronous gRPC channel (grpc.aio.Channel) does not have separate attributes for each call type (like _unary_unary_interceptors, _unary_stream_interceptors, etc.). Those are specific to the synchronous grpc.Channel implementation.

Instead, grpc.aio.Channel stores all its interceptors in a single list attribute named _interceptors. Because of this, the current hasattr checks will always evaluate to False, and the AsyncMetricsInterceptor will never be attached to the channel.

To fix this, check for and append to _interceptors instead.

                  if hasattr(self._grpc_channel, "_interceptors"):
                      self._grpc_channel._interceptors.append(
                          self._metrics_interceptor
                      )


self._interceptor = _LoggingClientAIOInterceptor()
count: 1
- paths: [packages/google-cloud-spanner/setup.py]
before: '(?s)dependencies = \[.*?\]\nextras = \{\s*\}'
after: |
Expand Down
Loading