diff --git a/gapic/templates/%namespace/%name_%version/%sub/services/%service/transports/rest.py.j2 b/gapic/templates/%namespace/%name_%version/%sub/services/%service/transports/rest.py.j2 index 4e69136b46..825756eb54 100644 --- a/gapic/templates/%namespace/%name_%version/%sub/services/%service/transports/rest.py.j2 +++ b/gapic/templates/%namespace/%name_%version/%sub/services/%service/transports/rest.py.j2 @@ -262,17 +262,24 @@ class {{service.name}}RestTransport(_Base{{ service.name }}RestTransport): resp = self._interceptor.post_{{ method.name|snake_case }}(resp) response_metadata = [(k, str(v)) for k, v in response.headers.items()] resp, _ = self._interceptor.post_{{ method.name|snake_case }}_with_metadata(resp, response_metadata) - {# TODO(https://github.com/googleapis/gapic-generator-python/issues/2279): Add logging support for rest streaming. #} - {% if not method.server_streaming %} if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(logging.DEBUG): # pragma: NO COVER + {# TODO(https://github.com/googleapis/gapic-generator-python/issues/2389): #} + {# Depending how we want to log (a) receiving a streaming response vs (b) exposing the next streamed item to the user, we could possibly want to log something here #} + {# (a) should always happen in api-core #} + {# (b) could happen in api-core, or it could happen here when we iterate to the next streamed item that was previously received. #} + {% if not method.server_streaming %} try: response_payload = {% if method.output.ident.is_proto_plus_type %}{{ method.output.ident }}.to_json(response){% else %}json_format.MessageToJson(resp){% endif %} except: {# TODO(https://github.com/googleapis/gapic-generator-python/issues/2283): Remove try/except once unit tests are updated. #} response_payload = None + {% endif %}{# if not method.server_streaming #} http_response = { + {# Not logging response payload for server streaming here. See comment above. #} + {% if not method.server_streaming %} "payload": response_payload, + {% endif %}{# if not method.server_streaming #} "headers": dict(response.headers), "status": response.status_code, } @@ -286,7 +293,6 @@ class {{service.name}}RestTransport(_Base{{ service.name }}RestTransport): "httpResponse": http_response, }, ) - {% endif %}{# if not method.server_streaming #} return resp {% endif %}{# method.void #} diff --git a/gapic/templates/%namespace/%name_%version/%sub/services/%service/transports/rest_asyncio.py.j2 b/gapic/templates/%namespace/%name_%version/%sub/services/%service/transports/rest_asyncio.py.j2 index 3de616d022..1d6ec87374 100644 --- a/gapic/templates/%namespace/%name_%version/%sub/services/%service/transports/rest_asyncio.py.j2 +++ b/gapic/templates/%namespace/%name_%version/%sub/services/%service/transports/rest_asyncio.py.j2 @@ -222,17 +222,24 @@ class Async{{service.name}}RestTransport(_Base{{ service.name }}RestTransport): resp = await self._interceptor.post_{{ method.name|snake_case }}(resp) response_metadata = [(k, str(v)) for k, v in response.headers.items()] resp, _ = await self._interceptor.post_{{ method.name|snake_case }}_with_metadata(resp, response_metadata) - {# TODO(https://github.com/googleapis/gapic-generator-python/issues/2279): Add logging support for rest streaming. #} - {% if not method.server_streaming %} if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(logging.DEBUG): # pragma: NO COVER + {# TODO(https://github.com/googleapis/gapic-generator-python/issues/2389): #} + {# Depending how we want to log (a) receiving a streaming response vs (b) exposing the next streamed item to the user, we could possibly want to log something here #} + {# (a) should always happen in api-core #} + {# (b) could happen in api-core, or it could happen here when we iterate to the next streamed item that was previously received. #} + {% if not method.server_streaming %} try: response_payload = {% if method.output.ident.is_proto_plus_type %}{{ method.output.ident }}.to_json(response){% else %}json_format.MessageToJson(resp){% endif %} except: {# TODO(https://github.com/googleapis/gapic-generator-python/issues/2283): Remove try/except once unit tests are updated. #} response_payload = None + {% endif %}{# if not method.server_streaming #} http_response = { + {# Not logging response payload for server streaming here. See comment above. #} + {% if not method.server_streaming %} "payload": response_payload, + {% endif %}{# if not method.server_streaming #} "headers": dict(response.headers), "status": "OK", # need to obtain this properly } @@ -246,7 +253,6 @@ class Async{{service.name}}RestTransport(_Base{{ service.name }}RestTransport): }, ) - {% endif %}{# if not method.server_streaming #} return resp {% endif %}{# method.void #}