[Fix] Fix structured logs in cronjobs#4841
Merged
Merged
Conversation
vitaliset
approved these changes
Jun 27, 2025
vitaliset
reviewed
Jun 27, 2025
vitorguidi
approved these changes
Jun 30, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Background
In #4781, it was necessary to add a logs filter to propagate the structured fields into GCP Logging for cronjobs in GAE/GKE (this is an unfortunate workaround due to different log configurations set depending on the environment).
However, the way this filter was implemented broke some of the logs, when non-serializable arguments were passed to the python logging extras fields. Thus, we disabled it in #4794.
Description
This fix updates the logs filter (responsible for adding
extrasinto thejson_fieldsfor GCP logging) by checking whether the values in logsextrasare JSON serializable and calling the_handle_unserializable()function for the negative cases, which simply converts them into strings.By doing this, we avoid the type errors that occurred in GCP (
TypeError: Object is not JSON serializable) while also maintaining the structure of the json for indexed queries.Tests
In order to test in the GKE environment, I leveraged our development environment with candidate release. I deployed a debug cronjob (
debug-logs) calling the same log entry that broke the cleanup cronjob before.The test results, before and after landing the fix, were:
Current fail state (link to logs):


After the fix (link to logs):


Also, in order to verify if the structured json fields were correctly maintained, I added a more complex log entry:
b/417782114