Skip to content

Commit b87ced6

Browse files
committed
Standardize logging fields
1 parent 71390a1 commit b87ced6

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

gapic/templates/%namespace/%name_%version/%sub/services/%service/_shared_macros.j2

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ def _get_http_options():
195195
Args:
196196
body_spec (str): The http options body i.e. method.http_options[0].body
197197
method_name (str): The method name.
198-
service_name (str): The service name.
198+
service: The service.
199199
is_async (bool): Used to determine the code path i.e. whether for sync or async call. #}
200200
{% macro rest_call_method_common(body_spec, method_name, service, is_async=False) %}
201201
{% set service_name = service.name %}
@@ -216,15 +216,18 @@ def _get_http_options():
216216
if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(logging.DEBUG): # pragma: NO COVER
217217
request_url = "{host}{uri}".format(host=self._host, uri=transcoded_request['uri'])
218218
method = transcoded_request['method']
219+
http_request = {
220+
"payload": type(request).to_json(request),
221+
"requestmethod": method,
222+
"requestUrl": request_url,
223+
}
219224
_LOGGER.debug(
220-
f"Sending request via {{ service.meta.address.proto_package_versioned }}.{{ service.client_name }}.{{ method_name }}",
225+
f"Sending request for {{ service.meta.address.proto_package_versioned }}.{{ service.client_name }}.{{ method_name }}",
221226
extra = {
222227
"serviceName": "{{ service.meta.address.proto }}",
223228
"rpcName": "{{ method_name }}",
224-
"httpRequest": type(request).to_json(request),
225-
"httpRequestMethod": method,
226-
"httpRequestUrl": request_url,
227229
"metadata": str(dict(metadata)),
230+
"httpRequest": http_request,
228231
},
229232
)
230233

gapic/templates/%namespace/%name_%version/%sub/services/%service/transports/rest.py.j2

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,13 +256,17 @@ class {{service.name}}RestTransport(_Base{{ service.name }}RestTransport):
256256
{% endif %}{# method.lro #}
257257
resp = self._interceptor.post_{{ method.name|snake_case }}(resp)
258258
if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(logging.DEBUG): # pragma: NO COVER
259+
http_response = {
260+
"payload": {% if method.output.ident.is_proto_plus_type %}{{ method.output.ident }}.to_json(resp){% else %}json_format.MessageToJson(resp){% endif %},
261+
"status": "OK", # need to obtain this properly
262+
}
259263
_LOGGER.debug(
260264
"Received response for {{ service.meta.address.proto_package_versioned }}.{{ service.client_name }}.{{ method.transport_safe_name|snake_case }}",
261265
extra = {
262266
"serviceName": "{{ service.meta.address.proto }}",
263267
"rpcName": "{{ method.name }}",
264-
"response": {% if method.output.ident.is_proto_plus_type %}{{ method.output.ident }}.to_json(resp){% else %}json_format.MessageToJson(resp){% endif %},
265268
"metadata": str(dict(response.headers)),
269+
"httpResponse": http_response,
266270
},
267271
)
268272
return resp

gapic/templates/%namespace/%name_%version/%sub/services/%service/transports/rest_asyncio.py.j2

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,17 +218,21 @@ class Async{{service.name}}RestTransport(_Base{{ service.name }}RestTransport):
218218
{% endif %}{# if method.server_streaming #}
219219
resp = await self._interceptor.post_{{ method.name|snake_case }}(resp)
220220
if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(logging.DEBUG): # pragma: NO COVER
221+
http_response = {
222+
"payload": {% if method.output.ident.is_proto_plus_type %}{{ method.output.ident }}.to_json(response){% else %}json_format.MessageToJson(response){% endif %},
223+
"headers": str(dict(response.headers)),
224+
"status": "OK", # need to obtain this properly
225+
}
221226
_LOGGER.debug(
222227
"Received response for {{ service.meta.address.proto_package_versioned }}.{{ service.async_client_name }}.{{ method.transport_safe_name|snake_case }}",
223228
extra = {
224229
"serviceName": "{{ service.meta.address.proto }}",
225230
"rpcName": "{{ method.name }}",
226-
"retryAttempt": 1,
227-
"response": {% if method.output.ident.is_proto_plus_type %}{{ method.output.ident }}.to_json(response){% else %}json_format.MessageToJson(response){% endif %},
228-
"metadata": str(dict(response.headers)),
231+
"metadata": http_response["headers"],
232+
"httpResponse": http_response,
229233
},
230234
)
231-
235+
232236
return resp
233237

234238
{% endif %}{# method.void #}

0 commit comments

Comments
 (0)