-
Notifications
You must be signed in to change notification settings - Fork 55
fix: Made write_entries
raise ValueError
on ParseError
s
#958
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
Conversation
google/cloud/logging_v2/logger.py
Outdated
try: | ||
client.logging_api.write_entries(entries, partial_success=True) | ||
except Exception: | ||
_LOGGER.error("Failed to submit log message.", exc_info=True) |
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.
I don't think it's a good idea to just swallow all exceptions here. All grpc networking errors would now be ignored (ex bad IAM credentials), and users will have no idea anything is wrong unless they know to subscribe to the internal _LOGGER. And existing customers may have error handling logic in place that will now be bypassed, so this could be a breaking change hidden in a bug fix
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.
Could we just do json_format.ParseError
s instead?
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.
You mean swallowing the specific exception instead of all exceptions?
Honestly, I think just raising an exception here makes sense, so the user knows their input isn't handled. I'd do a raise ValueError(...) from e
though, so we can give more context instead of raising the raw internal error. And then add a Raises:
section in the docstring describing this situation
google/cloud/logging_v2/logger.py
Outdated
info (dict): | ||
the log entry information. The dict must be serializable | ||
to a Protobuf Struct (map from strings to Values, see | ||
https://protobuf.dev/reference/protobuf/google.protobuf/#value), |
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.
is it possible to lay out the specific types that are serializable?
Nested dicts and lists could make it complicated. But maybe we could do something like dict[str, float|bool|str|dict|list|None]
google/cloud/logging_v2/logger.py
Outdated
the log entry information. The dict must be serializable | ||
to a Protobuf Struct (map from strings to Values, see | ||
https://protobuf.dev/reference/protobuf/google.protobuf/#value), | ||
otherwise the item will not be logged. |
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.
it might be good to add more info to the main text too, instead of "Log a dictionary message"
google/cloud/logging_v2/logger.py
Outdated
# attempt to attach extra contex on which log caused error | ||
self._append_context_to_error(e) | ||
raise e | ||
except Exception as e: |
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.
same comment as above: hiding exceptions by default seems like it could have unintentional consequences, and could be a breaking change
logging_api.write_entries
errors internally rather than crashingwrite_entries
raise ValueError
on ParseError
s
google/cloud/logging_v2/logger.py
Outdated
|
||
See | ||
https://cloud.google.com/logging/docs/reference/v2/rest/v2/entries/write | ||
|
||
The dictionary entry must be able to be serializable to a Protobuf Struct | ||
(see https://protobuf.dev/reference/protobuf/google.protobuf/#value for more | ||
details), otherwise it will not be logged. |
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.
"Otherwise a ValueError exception will be raised?"
Also, maybe include that this essentially means strings, floats, bools, lists, and dicts, and None?
Two fixes for #943:
write_entries
raiseValueError
on invalid log entries.log_struct
and clarifying theValueError
that gets raised.