Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -258,17 +258,25 @@ 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
{# Logging of the streaming response payload is in `google-api-core` because the response #}
Copy link
Contributor

Choose a reason for hiding this comment

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

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.

Ditto for async

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I filed #2389 to follow up on this and I also captured this comment in the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated comments in 58d6a89

{# type `rest_streaming.ResponseIterator` is an iterator. #}
{# Each response 'item' is logged at the time that it is fetched which happens in google-api-core. #}
{% 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 = {
{# Logging of the streaming response payload is in `google-api-core` because the response #}
{# type `rest_streaming.ResponseIterator` is an iterator. #}
{# Each response 'item' is logged at the time that it is fetched which happens in google-api-core. #}
{% if not method.server_streaming %}
"payload": response_payload,
{% endif %}{# if not method.server_streaming #}
"headers": dict(response.headers),
"status": response.status_code,
}
Expand All @@ -282,7 +290,6 @@ class {{service.name}}RestTransport(_Base{{ service.name }}RestTransport):
"httpResponse": http_response,
},
)
{% endif %}{# if not method.server_streaming #}
return resp

{% endif %}{# method.void #}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,17 +219,25 @@ 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
{# Logging of the streaming response payload is in `google-api-core` because the response #}
{# type `rest_streaming_async.AsyncResponseIterator` is an iterator. #}
{# Each response 'item' is logged at the time that it is fetched which happens in google-api-core. #}
{% 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 = {
{# Logging of the streaming response payload is in `google-api-core` because the response #}
{# type `rest_streaming_async.AsyncResponseIterator` is an iterator. #}
{# Each response 'item' is logged at the time that it is fetched which happens in google-api-core. #}
{% 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
}
Expand All @@ -243,7 +251,6 @@ class Async{{service.name}}RestTransport(_Base{{ service.name }}RestTransport):
},
)

{% endif %}{# if not method.server_streaming #}
return resp

{% endif %}{# method.void #}
Expand Down
Loading