-
Notifications
You must be signed in to change notification settings - Fork 95
feat: add client debug logging support for streaming gRPC/REST calls #794
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
2123298
5510056
3fb362f
d73d18c
826c79b
230fe9a
9fac30c
56810ca
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,7 @@ | |
| """Helpers for server-side streaming in REST.""" | ||
|
|
||
| from collections import deque | ||
| import logging | ||
| import string | ||
| from typing import Deque, Union | ||
| import types | ||
|
|
@@ -23,6 +24,8 @@ | |
| import google.protobuf.message | ||
| from google.protobuf.json_format import Parse | ||
|
|
||
| _LOGGER = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| class BaseResponseIterator: | ||
| """Base Iterator over REST API responses. This class should not be used directly. | ||
|
|
@@ -97,19 +100,38 @@ def _process_chunk(self, chunk: str): | |
| self._obj += char | ||
| self._escape_next = not self._escape_next if char == "\\" else False | ||
|
|
||
| def _log_response_payload(self, response_payload: str): | ||
| rest_response = { | ||
| "payload": response_payload, | ||
| "status": "OK", | ||
| } | ||
| _LOGGER.debug( | ||
| "Received response via REST stream", | ||
| extra={ | ||
| "response": rest_response, | ||
|
Comment on lines
+104
to
+111
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure we should be using/reference any sort of HTTP response here at all. This helper is being called from We should log http responses where we actually receive the HTTP chunks. |
||
| }, | ||
| ) | ||
|
|
||
| def _create_grab(self): | ||
| logging_enabled = _LOGGER.isEnabledFor(logging.DEBUG) | ||
| if issubclass(self._response_message_cls, proto.Message): | ||
|
|
||
| def grab(this): | ||
| result = this._ready_objs.popleft() | ||
| if logging_enabled: # pragma: NO COVER | ||
| self._log_result(result) | ||
| return this._response_message_cls.from_json( | ||
| this._ready_objs.popleft(), ignore_unknown_fields=True | ||
| result, ignore_unknown_fields=True | ||
| ) | ||
|
|
||
| return grab | ||
| elif issubclass(self._response_message_cls, google.protobuf.message.Message): | ||
|
|
||
| def grab(this): | ||
| return Parse(this._ready_objs.popleft(), this._response_message_cls()) | ||
| result = this._ready_objs.popleft() | ||
| if logging_enabled: # pragma: NO COVER | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we add coverage for this? |
||
| self._log_result(result) | ||
| return Parse(result, this._response_message_cls()) | ||
|
|
||
| return grab | ||
| else: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we be using
httpResponsehere instead for structured logs?