Skip to content
Draft
Show file tree
Hide file tree
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 @@ -333,21 +333,25 @@ class {{ service.grpc_asyncio_transport_name }}({{ service.name }}Transport):
],
)

# Wrap channel with user-specified and logging interceptors.
channel_interceptors = list(interceptors) if interceptors else []
self._interceptor = _LoggingClientAIOInterceptor()
channel_interceptors.append(self._interceptor)
self._grpc_channel = apply_async_channel_interceptors(
self._grpc_channel, channel_interceptors
)

# Configure OpenTelemetry tracing and span suppression on the channel.
if (
_observability is not None
and (otel_interceptors := _observability.get_otel_async_interceptor(self._client_options)) is not None
and hasattr(_observability, "apply_otel_async_channel_interceptors")
):
# NOTE: Coverage tool ignores async interceptors in environments running
# legacy google-api-core (< 2.36.0) where OpenTelemetry is unavailable.
# Lifecycle: Can be lifted once lowest constraints require google-api-core >= 2.36.0.
otel_list = otel_interceptors if isinstance(otel_interceptors, (list, tuple)) else [otel_interceptors] # pragma: NO COVER
channel_interceptors.extend(otel_list) # pragma: NO COVER

self._grpc_channel = apply_async_channel_interceptors(self._grpc_channel, channel_interceptors)
# TODO (Issue #18657): Remove once lowest constraints require google-api-core >= v2.43.0.
self._grpc_channel = _observability.apply_otel_async_channel_interceptors(
self._grpc_channel, self._client_options
) # pragma: NO COVER

self._logged_channel = self._grpc_channel
# Wrap messages. This must be done after self._logged_channel exists
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1045,20 +1045,19 @@ def test_{{ service.name|snake_case }}_grpc_asyncio_transport_channel_intercepto


@pytest.mark.skipif(
_observability is None,
reason="Requires google-api-core with OpenTelemetry support (>= 2.36.0)",
_observability is None or not hasattr(_observability, "apply_otel_async_channel_interceptors"),
reason="Requires google-api-core with OpenTelemetry async channel interceptors support (>= v2.43.0)",
)
def test_{{ service.name|snake_case }}_grpc_asyncio_transport_otel_channel_interceptor():
mock_otel_interceptor = mock.Mock()
mock_channel = mock.Mock()
mock_channel._unary_unary_interceptors = []

with (
mock.patch.object(
_observability,
"get_otel_async_interceptor",
return_value=mock_otel_interceptor,
) as mock_get_async_interceptor,
"apply_otel_async_channel_interceptors",
return_value=mock_channel,
) as mock_apply_async_interceptors,
mock.patch.object(
transports.{{ service.grpc_asyncio_transport_name }},
"create_channel",
Expand All @@ -1071,9 +1070,8 @@ def test_{{ service.name|snake_case }}_grpc_asyncio_transport_otel_channel_inter
client_options=options,
)

mock_get_async_interceptor.assert_called_once_with(options)
mock_apply_async_interceptors.assert_called_once_with(mock_channel, options)
assert mock_create_channel.call_count == 1
assert mock_otel_interceptor in transport.grpc_channel._unary_unary_interceptors
assert transport.grpc_channel == mock_channel


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,21 +319,25 @@ def __init__(self, *,
],
)

# Wrap channel with user-specified and logging interceptors.
channel_interceptors = list(interceptors) if interceptors else []
self._interceptor = _LoggingClientAIOInterceptor()
channel_interceptors.append(self._interceptor)
self._grpc_channel = apply_async_channel_interceptors(
self._grpc_channel, channel_interceptors
)

# Configure OpenTelemetry tracing and span suppression on the channel.
if (
_observability is not None
and (otel_interceptors := _observability.get_otel_async_interceptor(self._client_options)) is not None
and hasattr(_observability, "apply_otel_async_channel_interceptors")
):
# NOTE: Coverage tool ignores async interceptors in environments running
# legacy google-api-core (< 2.36.0) where OpenTelemetry is unavailable.
# Lifecycle: Can be lifted once lowest constraints require google-api-core >= 2.36.0.
otel_list = otel_interceptors if isinstance(otel_interceptors, (list, tuple)) else [otel_interceptors] # pragma: NO COVER
channel_interceptors.extend(otel_list) # pragma: NO COVER

self._grpc_channel = apply_async_channel_interceptors(self._grpc_channel, channel_interceptors)
# TODO (Issue #18657): Remove once lowest constraints require google-api-core >= 2.36.0.
self._grpc_channel = _observability.apply_otel_async_channel_interceptors(
self._grpc_channel, self._client_options
) # pragma: NO COVER

self._logged_channel = self._grpc_channel
# Wrap messages. This must be done after self._logged_channel exists
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -900,20 +900,19 @@ def test_asset_service_grpc_asyncio_transport_channel_interceptors():


@pytest.mark.skipif(
_observability is None,
reason="Requires google-api-core with OpenTelemetry support (>= 2.36.0)",
_observability is None or not hasattr(_observability, "apply_otel_async_channel_interceptors"),
reason="Requires google-api-core with OpenTelemetry async channel interceptors support",
)
def test_asset_service_grpc_asyncio_transport_otel_channel_interceptor():
mock_otel_interceptor = mock.Mock()
mock_channel = mock.Mock()
mock_channel._unary_unary_interceptors = []

with (
mock.patch.object(
_observability,
"get_otel_async_interceptor",
return_value=mock_otel_interceptor,
) as mock_get_async_interceptor,
"apply_otel_async_channel_interceptors",
return_value=mock_channel,
) as mock_apply_async_interceptors,
mock.patch.object(
transports.AssetServiceGrpcAsyncIOTransport,
"create_channel",
Expand All @@ -926,9 +925,8 @@ def test_asset_service_grpc_asyncio_transport_otel_channel_interceptor():
client_options=options,
)

mock_get_async_interceptor.assert_called_once_with(options)
mock_apply_async_interceptors.assert_called_once_with(mock_channel, options)
assert mock_create_channel.call_count == 1
assert mock_otel_interceptor in transport.grpc_channel._unary_unary_interceptors
assert transport.grpc_channel == mock_channel


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,21 +324,25 @@ def __init__(self, *,
],
)

# Wrap channel with user-specified and logging interceptors.
channel_interceptors = list(interceptors) if interceptors else []
self._interceptor = _LoggingClientAIOInterceptor()
channel_interceptors.append(self._interceptor)
self._grpc_channel = apply_async_channel_interceptors(
self._grpc_channel, channel_interceptors
)

# Configure OpenTelemetry tracing and span suppression on the channel.
if (
_observability is not None
and (otel_interceptors := _observability.get_otel_async_interceptor(self._client_options)) is not None
and hasattr(_observability, "apply_otel_async_channel_interceptors")
):
# NOTE: Coverage tool ignores async interceptors in environments running
# legacy google-api-core (< 2.36.0) where OpenTelemetry is unavailable.
# Lifecycle: Can be lifted once lowest constraints require google-api-core >= 2.36.0.
otel_list = otel_interceptors if isinstance(otel_interceptors, (list, tuple)) else [otel_interceptors] # pragma: NO COVER
channel_interceptors.extend(otel_list) # pragma: NO COVER

self._grpc_channel = apply_async_channel_interceptors(self._grpc_channel, channel_interceptors)
# TODO (Issue #18657): Remove once lowest constraints require google-api-core >= 2.36.0.
self._grpc_channel = _observability.apply_otel_async_channel_interceptors(
self._grpc_channel, self._client_options
) # pragma: NO COVER

self._logged_channel = self._grpc_channel
# Wrap messages. This must be done after self._logged_channel exists
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -890,20 +890,19 @@ def test_iam_credentials_grpc_asyncio_transport_channel_interceptors():


@pytest.mark.skipif(
_observability is None,
reason="Requires google-api-core with OpenTelemetry support (>= 2.36.0)",
_observability is None or not hasattr(_observability, "apply_otel_async_channel_interceptors"),
reason="Requires google-api-core with OpenTelemetry async channel interceptors support",
)
def test_iam_credentials_grpc_asyncio_transport_otel_channel_interceptor():
mock_otel_interceptor = mock.Mock()
mock_channel = mock.Mock()
mock_channel._unary_unary_interceptors = []

with (
mock.patch.object(
_observability,
"get_otel_async_interceptor",
return_value=mock_otel_interceptor,
) as mock_get_async_interceptor,
"apply_otel_async_channel_interceptors",
return_value=mock_channel,
) as mock_apply_async_interceptors,
mock.patch.object(
transports.IAMCredentialsGrpcAsyncIOTransport,
"create_channel",
Expand All @@ -916,9 +915,8 @@ def test_iam_credentials_grpc_asyncio_transport_otel_channel_interceptor():
client_options=options,
)

mock_get_async_interceptor.assert_called_once_with(options)
mock_apply_async_interceptors.assert_called_once_with(mock_channel, options)
assert mock_create_channel.call_count == 1
assert mock_otel_interceptor in transport.grpc_channel._unary_unary_interceptors
assert transport.grpc_channel == mock_channel


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,21 +333,25 @@ def __init__(self, *,
],
)

# Wrap channel with user-specified and logging interceptors.
channel_interceptors = list(interceptors) if interceptors else []
self._interceptor = _LoggingClientAIOInterceptor()
channel_interceptors.append(self._interceptor)
self._grpc_channel = apply_async_channel_interceptors(
self._grpc_channel, channel_interceptors
)

# Configure OpenTelemetry tracing and span suppression on the channel.
if (
_observability is not None
and (otel_interceptors := _observability.get_otel_async_interceptor(self._client_options)) is not None
and hasattr(_observability, "apply_otel_async_channel_interceptors")
):
# NOTE: Coverage tool ignores async interceptors in environments running
# legacy google-api-core (< 2.36.0) where OpenTelemetry is unavailable.
# Lifecycle: Can be lifted once lowest constraints require google-api-core >= 2.36.0.
otel_list = otel_interceptors if isinstance(otel_interceptors, (list, tuple)) else [otel_interceptors] # pragma: NO COVER
channel_interceptors.extend(otel_list) # pragma: NO COVER

self._grpc_channel = apply_async_channel_interceptors(self._grpc_channel, channel_interceptors)
# TODO (Issue #18657): Remove once lowest constraints require google-api-core >= 2.36.0.
self._grpc_channel = _observability.apply_otel_async_channel_interceptors(
self._grpc_channel, self._client_options
) # pragma: NO COVER

self._logged_channel = self._grpc_channel
# Wrap messages. This must be done after self._logged_channel exists
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -921,20 +921,19 @@ def test_eventarc_grpc_asyncio_transport_channel_interceptors():


@pytest.mark.skipif(
_observability is None,
reason="Requires google-api-core with OpenTelemetry support (>= 2.36.0)",
_observability is None or not hasattr(_observability, "apply_otel_async_channel_interceptors"),
reason="Requires google-api-core with OpenTelemetry async channel interceptors support",
)
def test_eventarc_grpc_asyncio_transport_otel_channel_interceptor():
mock_otel_interceptor = mock.Mock()
mock_channel = mock.Mock()
mock_channel._unary_unary_interceptors = []

with (
mock.patch.object(
_observability,
"get_otel_async_interceptor",
return_value=mock_otel_interceptor,
) as mock_get_async_interceptor,
"apply_otel_async_channel_interceptors",
return_value=mock_channel,
) as mock_apply_async_interceptors,
mock.patch.object(
transports.EventarcGrpcAsyncIOTransport,
"create_channel",
Expand All @@ -947,9 +946,8 @@ def test_eventarc_grpc_asyncio_transport_otel_channel_interceptor():
client_options=options,
)

mock_get_async_interceptor.assert_called_once_with(options)
mock_apply_async_interceptors.assert_called_once_with(mock_channel, options)
assert mock_create_channel.call_count == 1
assert mock_otel_interceptor in transport.grpc_channel._unary_unary_interceptors
assert transport.grpc_channel == mock_channel


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,21 +319,25 @@ def __init__(self, *,
],
)

# Wrap channel with user-specified and logging interceptors.
channel_interceptors = list(interceptors) if interceptors else []
self._interceptor = _LoggingClientAIOInterceptor()
channel_interceptors.append(self._interceptor)
self._grpc_channel = apply_async_channel_interceptors(
self._grpc_channel, channel_interceptors
)

# Configure OpenTelemetry tracing and span suppression on the channel.
if (
_observability is not None
and (otel_interceptors := _observability.get_otel_async_interceptor(self._client_options)) is not None
and hasattr(_observability, "apply_otel_async_channel_interceptors")
):
# NOTE: Coverage tool ignores async interceptors in environments running
# legacy google-api-core (< 2.36.0) where OpenTelemetry is unavailable.
# Lifecycle: Can be lifted once lowest constraints require google-api-core >= 2.36.0.
otel_list = otel_interceptors if isinstance(otel_interceptors, (list, tuple)) else [otel_interceptors] # pragma: NO COVER
channel_interceptors.extend(otel_list) # pragma: NO COVER

self._grpc_channel = apply_async_channel_interceptors(self._grpc_channel, channel_interceptors)
# TODO (Issue #18657): Remove once lowest constraints require google-api-core >= 2.36.0.
self._grpc_channel = _observability.apply_otel_async_channel_interceptors(
self._grpc_channel, self._client_options
) # pragma: NO COVER

self._logged_channel = self._grpc_channel
# Wrap messages. This must be done after self._logged_channel exists
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,21 +317,25 @@ def __init__(self, *,
],
)

# Wrap channel with user-specified and logging interceptors.
channel_interceptors = list(interceptors) if interceptors else []
self._interceptor = _LoggingClientAIOInterceptor()
channel_interceptors.append(self._interceptor)
self._grpc_channel = apply_async_channel_interceptors(
self._grpc_channel, channel_interceptors
)

# Configure OpenTelemetry tracing and span suppression on the channel.
if (
_observability is not None
and (otel_interceptors := _observability.get_otel_async_interceptor(self._client_options)) is not None
and hasattr(_observability, "apply_otel_async_channel_interceptors")
):
# NOTE: Coverage tool ignores async interceptors in environments running
# legacy google-api-core (< 2.36.0) where OpenTelemetry is unavailable.
# Lifecycle: Can be lifted once lowest constraints require google-api-core >= 2.36.0.
otel_list = otel_interceptors if isinstance(otel_interceptors, (list, tuple)) else [otel_interceptors] # pragma: NO COVER
channel_interceptors.extend(otel_list) # pragma: NO COVER

self._grpc_channel = apply_async_channel_interceptors(self._grpc_channel, channel_interceptors)
# TODO (Issue #18657): Remove once lowest constraints require google-api-core >= 2.36.0.
self._grpc_channel = _observability.apply_otel_async_channel_interceptors(
self._grpc_channel, self._client_options
) # pragma: NO COVER

self._logged_channel = self._grpc_channel
# Wrap messages. This must be done after self._logged_channel exists
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,21 +317,25 @@ def __init__(self, *,
],
)

# Wrap channel with user-specified and logging interceptors.
channel_interceptors = list(interceptors) if interceptors else []
self._interceptor = _LoggingClientAIOInterceptor()
channel_interceptors.append(self._interceptor)
self._grpc_channel = apply_async_channel_interceptors(
self._grpc_channel, channel_interceptors
)

# Configure OpenTelemetry tracing and span suppression on the channel.
if (
_observability is not None
and (otel_interceptors := _observability.get_otel_async_interceptor(self._client_options)) is not None
and hasattr(_observability, "apply_otel_async_channel_interceptors")
):
# NOTE: Coverage tool ignores async interceptors in environments running
# legacy google-api-core (< 2.36.0) where OpenTelemetry is unavailable.
# Lifecycle: Can be lifted once lowest constraints require google-api-core >= 2.36.0.
otel_list = otel_interceptors if isinstance(otel_interceptors, (list, tuple)) else [otel_interceptors] # pragma: NO COVER
channel_interceptors.extend(otel_list) # pragma: NO COVER

self._grpc_channel = apply_async_channel_interceptors(self._grpc_channel, channel_interceptors)
# TODO (Issue #18657): Remove once lowest constraints require google-api-core >= 2.36.0.
self._grpc_channel = _observability.apply_otel_async_channel_interceptors(
self._grpc_channel, self._client_options
) # pragma: NO COVER

self._logged_channel = self._grpc_channel
# Wrap messages. This must be done after self._logged_channel exists
Expand Down
Loading
Loading